Your first module
We'll create a very simple module Person for understanding how is very simple to create new modules with Uccello.
The creation of a new module involves three steps:
Create a model and a table that will contain the data
Create the module's structure that will generate the views
Create a language file
First of all, let's create a new model:
php artisan make:model PersonThis command line creates the file app/Person.php.
Use UccelloModule trait and define the label to use for each record:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Uccello\Core\Support\Traits\UccelloModule;
class Person extends Model
{
use UccelloModule;
use SoftDeletes;
/**
* Returns record label
*
* @return string
*/
public function getRecordLabelAttribute() : string
{
return trim($this->first_name.' '.$this->last_name);
}
}Now we can create a new migration:
This command line creates the file database/migrations/DATE_create_people_module.php.
Put this code to create the people table:
Now we want to create the module's structure. Let's add the following code into the migration file:
Now we can run the migration with the following commands:
Finally we can create a new language file resources/lang/en/person.php:
The file's name must be the same as the module's name. Here we create the file person.php because the module's name is person.
Congratulations! Your first module is available here: http://localhost:8000/person/list.
Last updated
Was this helpful?