php artisan make:model Person
php artisan make:migration create_person_module
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePersonModule extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('people', function (Blueprint $table) {
$table->increments('id');
$table->string('first_name');
$table->string('last_name');
$table->date('birthday')->nullable();
$table->unsignedInteger('domain_id');
$table->timestamps();
$table->datetime('deleted_at')->nullable();
$table->foreign('domain_id')->references('id')->on('uccello_domains');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('people');
}
}
<?php
...
use Uccello\Core\Models\Domain;
use Uccello\Core\Models\Module;
use Uccello\Core\Models\Tab;
use Uccello\Core\Models\Block;
use Uccello\Core\Models\Field;
use Uccello\Core\Models\Filter;
class CreatePersonModule extends Migration
{
public function up()
{
...
// Create the module's structure
$this->createModuleStructure();
}
public function down()
{
...
// Remove automaticaly the module and its structure
Module::where('name', 'person')->delete();
}
/**
* Create the module's structure.
*/
protected function createModuleStructure()
{
$module = $this->createModule();
$this->createTabsBlocksFields($module);
$this->createFilters($module);
$this->activateModuleOnDomains($module);
}
/**
* Create the module.
*/
protected function createModule()
{
return Module::create([
'name' => 'person',
'icon' => 'person',
'model_class' => 'App\Person',
'data' => null
]);
}
/**
* Activate module in all domains
*/
protected function activateModuleOnDomains($module)
{
$domains = Domain::all();
foreach ($domains as $domain) {
$domain->modules()->attach($module);
}
}
/**
* Create all tabs, blocks and fields.
*/
protected function createTabsBlocksFields($module)
{
// Main tab
$tab = Tab::create([
'label' => 'tab.main',
'icon' => null,
'sequence' => $module->tabs()->count(),
'module_id' => $module->id
]);
// General block
$block = Block::create([
'label' => 'block.general',
'icon' => 'info',
'sequence' => $tab->blocks()->count(),
'tab_id' => $tab->id,
'module_id' => $module->id
]);
// First name
Field::create([
'name' => 'first_name',
'uitype_id' => uitype('text')->id,
'displaytype_id' => displaytype('everywhere')->id,
'data' => [ 'rules' => 'required' ],
'sequence' => $block->fields()->count(),
'block_id' => $block->id,
'module_id' => $module->id
]);
// Last name
Field::create([
'name' => 'last_name',
'uitype_id' => uitype('text')->id,
'displaytype_id' => displaytype('everywhere')->id,
'data' => [ 'rules' => 'required' ],
'sequence' => $block->fields()->count(),
'block_id' => $block->id,
'module_id' => $module->id
]);
// Birthday
Field::create([
'name' => 'birthday',
'uitype_id' => uitype('date')->id,
'displaytype_id' => displaytype('everywhere')->id,
'data' => null,
'sequence' => $block->fields()->count(),
'block_id' => $block->id,
'module_id' => $module->id
]);
}
/**
* Create the default filter.
*/
protected function createFilters($module)
{
Filter::create([
'module_id' => $module->id,
'domain_id' => null,
'user_id' => null,
'name' => 'filter.all',
'type' => 'list',
'columns' => [ 'first_name', 'last_name', 'birthday' ],
'conditions' => null,
'order' => null,
'is_default' => true,
'is_public' => false,
'data' => [ 'readonly' => true ],
]);
}
}
php artisan migrate
php artisan cache:clear
<?php
return [
'person' => 'People', // Translation of the module's name
'tab' => [
'main' => 'Detail',
],
'block' => [
'general' => 'General information',
],
'field' => [
'first_name' => 'First name',
'last_name' => 'Last name',
'birthday' => 'Birthday',
],
];