Make a Migration
A LaraAdmin module is created by a migration that calls LAModule::generate(). It creates the table and the module's rows in la_modules and la_module_fields. To create a migration file for a Courses module:
php artisan la:migration courses
# or
php artisan la:migration create_courses_table
This writes database/migrations/YYYY_MM_DD_HHMMSS_create_courses_table.php:
use App\Models\LAModule;
LAModule::generate('Courses', 'courses', 'name', 'fa-book', [
// the fields
]);
LAModule::generate() takes:
- Module name, plural:
Courses - Table name:
courses - View column: the column used as the record's title and link, e.g.
name. It must be one of the fields, in lowercase. - Font Awesome 4 icon:
fa-book,fa-group... - The fields, as an array
Field format
Each field is an array with these keys. Only colname, label and field_type are required:
[
'colname' => 'name', // column name: lowercase, words joined by _
'label' => 'Name', // label in forms and listings
'field_type' => 'Name', // one of the 31 field types below
'unique' => false, // values must be unique (max length becomes 250)
'defaultvalue' => '', // default value
'minlength' => 0, // min length / value / item count, 0 = none
'maxlength' => 250, // max length / value / item count, 0 = none
'required' => true, // required in the Add / Edit forms
'listing_col' => true, // shown in the listing table (default true)
'popup_vals' => '', // values: ['A', 'B'] or '@table_name'
'comment' => '', // optional note
]
| Key | Default | Description |
|---|---|---|
colname | required | Database column name. lowercase, words joined by underscores |
label | required | Label of the field, e.g. Name, Cost, Is Public |
field_type | required | One of the field types |
unique | false | Values must be unique. Checked when a record is added. |
defaultvalue | '' | Default value for new records and the column |
minlength / maxlength | 0 | Limits checked by the forms: length for text, value for numbers, number of items for Taginput, List and Checklist. For most text types maxlength is also the column length; 0 means no limit. |
required | false | Mandatory in the Add / Edit forms |
listing_col | true | Show as a column of the listing table |
popup_vals | '' | For Dropdown, Radio, Multiselect, Taginput: a list ['Draft', 'Published'], or '@table_name' to choose records of another module's table (stored by id, with a foreign key) |
A complete example:
LAModule::generate('Courses', 'courses', 'name', 'fa-book', [
[
'colname' => 'name',
'label' => 'Name',
'field_type' => 'Name',
'unique' => true,
'minlength' => 3,
'maxlength' => 250,
'required' => true,
], [
'colname' => 'teacher_id',
'label' => 'Teacher',
'field_type' => 'Dropdown',
'required' => true,
'popup_vals' => '@employees',
], [
'colname' => 'fees',
'label' => 'Fees',
'field_type' => 'Currency',
'defaultvalue' => 0,
'required' => true,
], [
'colname' => 'description',
'label' => 'Description',
'field_type' => 'Textarea',
'maxlength' => 1000,
'listing_col' => false,
],
]);
Then create the table:
php artisan migrate
The 1.0 format, a plain list ["name", "Name", "Name", true, "", 5, 256, true] (column, label, type, unique, default, min, max, required, values), still works.
Migration from an existing module
To write the migration of a module that already exists in the database (for example one you built in Module Manager), add --generate. It updates the module's existing migration file, or creates one:
php artisan la:migration courses --generate
This is what Module Manager's Update Migration button does. Commit the file so that other installs create the same table.
Field Types Reference
Columns are listed as MySQL types. Text columns are NULLable unless noted. A field linked to @table stores the record's id.
| Field type | Form input | Column | Min / Max | Values / default |
|---|---|---|---|---|
| Address | Text area | VARCHAR(max), TEXT if max is 0 | Length | |
| Checkbox | Toggle | TINYINT(1) | - | Default true / false |
| Checklist | To-do list with check boxes | TEXT (JSON) | Number of items | Items can be ticked from the record page |
| Color | Color picker | VARCHAR(25) | - | Default #000 |
| Currency | Number | DOUBLE (1.1: DOUBLE(15,2)) | - | Default 0.0 |
| Date | Date picker | DATE | - | A date such as 2026-01-31, or empty for none. The form shows dd/mm/yyyy. |
| Datetime | Date and time picker | TIMESTAMP | - | 2026-01-31 14:20:00, or now() (column default CURRENT_TIMESTAMP) |
| Decimal | Number | DECIMAL(15,2) | - | Default 0.0 |
| Dropdown | Select | VARCHAR for a list, BIGINT UNSIGNED + foreign key for @table | - | List or @table. Quick add (+) adds a record to the linked module. |
| Duration | Days / hours / minutes | INT UNSIGNED (minutes) | - | Default 0 |
VARCHAR(max), VARCHAR(100) if max is 0 | Length | |||
| File | Choose / upload a file | BIGINT UNSIGNED + foreign key to uploads | - | Stores an upload id |
| Files | Choose / upload several files | VARCHAR(256) (JSON list of upload ids) | - | Default [] |
| Float | Number | FLOAT | Length (checked as text) | |
| HTML | Rich text editor | VARCHAR(10000) | Length | |
| Image | Choose / upload an image | BIGINT UNSIGNED + foreign key to uploads | - | Stores an upload id |
| Integer | Number | INT NOT NULL | Value | Default 0 |
| JSON | Text | JSON | - | Default {} |
| List | Editable list of lines | TEXT (JSON) | Number of items | |
| Location | Map with address search, latitude and longitude | VARCHAR(30) (lat,lng) | - | Default 0.0,0.0. Needs the Google Maps script with your own API key: it is commented out in resources/views/la/layouts/partials/scripts.blade.php. |
| Mobile | Phone number | VARCHAR(max) | Length | |
| Multiselect | Multiple select | VARCHAR(256) (JSON list) | - | List or @table. Default [] or ["A"] / [2, 3] |
| Name | Text | VARCHAR(max) NOT NULL | Length | Good choice for the view column |
| Password | Password | VARCHAR(max) | Length | Stored hashed |
| Radio | Radio buttons | VARCHAR for a list, INT UNSIGNED for @table | - | List or @table |
| String | Text | VARCHAR(max) | Length | |
| Taginput | Tags | VARCHAR(1000) (JSON list) | Number of tags | Free tags, or a list / @table to choose from |
| Textarea | Text area | VARCHAR(max), TEXT if max is 0 | Length | |
| TextField | Text | VARCHAR(max) | Length | |
| Time | Time picker | VARCHAR(4) (HHMM, 24 h) | - | e.g. 0930, 1745 |
| URL | URL | VARCHAR(max) | Length |
A text column with max 0 gets Laravel's default length (255) unless noted.
Examples of every type
One field of each type, ready to paste into LAModule::generate():
['colname' => 'address', 'label' => 'Address', 'field_type' => 'Address', 'maxlength' => 1000],
['colname' => 'restricted', 'label' => 'Restricted', 'field_type' => 'Checkbox', 'defaultvalue' => false],
['colname' => 'todo', 'label' => 'To Do', 'field_type' => 'Checklist', 'listing_col' => false],
['colname' => 'color', 'label' => 'Color', 'field_type' => 'Color', 'defaultvalue' => '#3c8dbc'],
['colname' => 'price', 'label' => 'Price', 'field_type' => 'Currency', 'defaultvalue' => 0, 'required' => true],
['colname' => 'date_release', 'label' => 'Date of Release', 'field_type' => 'Date'],
['colname' => 'time_started', 'label' => 'Start Time', 'field_type' => 'Datetime', 'defaultvalue' => 'now()'],
['colname' => 'weight', 'label' => 'Weight', 'field_type' => 'Decimal', 'defaultvalue' => 0],
['colname' => 'status', 'label' => 'Status', 'field_type' => 'Dropdown', 'defaultvalue' => 'Draft', 'popup_vals' => ['Draft', 'Published']],
['colname' => 'dept', 'label' => 'Department', 'field_type' => 'Dropdown', 'required' => true, 'popup_vals' => '@departments'],
['colname' => 'duration', 'label' => 'Duration', 'field_type' => 'Duration'],
['colname' => 'email', 'label' => 'Email', 'field_type' => 'Email', 'unique' => true, 'maxlength' => 250],
['colname' => 'brochure', 'label' => 'Brochure', 'field_type' => 'File'],
['colname' => 'attachments', 'label' => 'Attachments', 'field_type' => 'Files', 'listing_col' => false],
['colname' => 'rating', 'label' => 'Rating', 'field_type' => 'Float'],
['colname' => 'biography', 'label' => 'Biography', 'field_type' => 'HTML', 'listing_col' => false],
['colname' => 'profile_image', 'label' => 'Profile Image', 'field_type' => 'Image'],
['colname' => 'pages', 'label' => 'Pages', 'field_type' => 'Integer', 'minlength' => 0, 'maxlength' => 5000],
['colname' => 'settings', 'label' => 'Settings', 'field_type' => 'JSON', 'defaultvalue' => '{}', 'listing_col' => false],
['colname' => 'features', 'label' => 'Features', 'field_type' => 'List', 'maxlength' => 10],
['colname' => 'location', 'label' => 'Location', 'field_type' => 'Location'],
['colname' => 'mobile', 'label' => 'Mobile', 'field_type' => 'Mobile', 'maxlength' => 20],
['colname' => 'media_type', 'label' => 'Media Type', 'field_type' => 'Multiselect', 'defaultvalue' => ['Print'], 'popup_vals' => ['Print', 'Audiobook', 'E-book']],
['colname' => 'name', 'label' => 'Name', 'field_type' => 'Name', 'minlength' => 3, 'maxlength' => 250, 'required' => true],
['colname' => 'password', 'label' => 'Password', 'field_type' => 'Password', 'minlength' => 6, 'maxlength' => 250, 'listing_col' => false],
['colname' => 'gender', 'label' => 'Gender', 'field_type' => 'Radio', 'defaultvalue' => 'Female', 'popup_vals' => ['Female', 'Male', 'Other']],
['colname' => 'author', 'label' => 'Author', 'field_type' => 'String', 'maxlength' => 250],
['colname' => 'genre', 'label' => 'Genre', 'field_type' => 'Taginput', 'defaultvalue' => ['Fantasy'], 'maxlength' => 5],
['colname' => 'description', 'label' => 'Description', 'field_type' => 'Textarea', 'maxlength' => 1000],
['colname' => 'short_intro', 'label' => 'Short Introduction', 'field_type' => 'TextField', 'maxlength' => 250],
['colname' => 'opens_at', 'label' => 'Opens At', 'field_type' => 'Time', 'defaultvalue' => '0930'],
['colname' => 'website', 'label' => 'Website', 'field_type' => 'URL', 'maxlength' => 250],
Generate CRUDs
Once the migration has run, one command generates the CRUD:
php artisan la:crud Courses
It generates the same files as Module Manager's Generate Migration + CRUD button:
- Controller
app/Http/Controllers/LA/CoursesController.php - Model
app/Models/Course.php - Observer
app/Observers/CourseObserver.php, registered inLAProvider - Views
resources/views/la/courses/(index, edit, show) - Language file
resources/lang/en/la_course.php - Routes appended to
routes/admin.php, and log types inconfig/laraadmin.php - A sidebar menu item
la:crud doesn't give the Super Admin access to the new module, so its pages redirect to the dashboard. Grant access in Roles, or in the module's Access tab in Module Manager. (Known issue.)
The generated code is built from the templates in app/Stubs/. To change what every new module looks like, edit those; see Customizing.