Your first module

We'll create a very simple module Person for understanding how is very simple to create new modules with Uccello.

Even if it is easier to create a module with Module Designer, we'll create it manually to understand how it works.

The creation of a new module involves three steps:

  1. Create a model and a table that will contain the data

  2. Create the module's structure that will generate the views

  3. Create a language file

First of all, let's create a new model:

php artisan make:model Person

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:

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:

Congratulations! Your first module is available here: http://localhost:8000/person/list.

Last updated

Was this helpful?