Make Migration
Generate migration file
Take example that you want to generate CRUD for Course.
php artisan la:migration Course
OR you can also use syntax like below:
php artisan la:migration create_course_table
Edit Migration
Command la:migration
generate the migration file which contains one method call Module::generate
:
Module::generate("Courses", 'courses', 'write_view_column_name_here e.g. name', 'fa-cube', [
// Write your columns here
]);
Module::generate
method has following parameters:
- 1. Module Name e.g. Courses
- 2. Database Table Name e.g. courses
- 3. View Column Name e.g. name / title
- 4. Font-Awesome Icon class e.g. fa-cube, fa-group
- 5. Array of Module Columns []
write_view_column_name_here
in lowercase only. If not set it will give error while migrated.
You need to configure your Column Schema within given array from examples given below:
Column format:
["col_name_db", "Label", "UI_Type", "Is_Unique", "Default_Val", "min_length", "max_length", "Is_Required", "values"]
1 | col_name_db | Database column name. lowercase, words concatenated by underscore (_) |
2 | Label | Label of Column e.g. Name, Cost, Is Public |
3 | UI_Type | It defines type of Column in more General way. Please see table for UI Types. |
4 | Is_Unique | Whether the column has unique values. Value in true / false |
5 | Default_Val | Default value for column. |
6 | min_length | Minimum Length of value in integer. |
7 | max_length | Maximum Length of value in integer. |
8 | Is_Required | Is this mandatory field in Add / Edit forms. Value in true / false |
9 | values | This is for MultiSelect, TagInput and Radio Columns. |
["name", 'Name', 'Name', true, 'John Doe', 5, 256, true],
UI / Data Types
There are around 24 Data Types supported as of now. There will be more in future.
UI Type (3rd) | Default Value (5th) | Min Length (6th) | Max Length (7th) | Popup Values (9th) |
---|---|---|---|---|
Address | In String | Integer | Integer | |
Checkbox | true / false | 0 | 0 | |
Currency | In Decimal | Minimum Value | Maximum Value | |
Date | now() 2016-06-23 | 0 | 0 | |
Datetime | now() 2016-06-23 14:20:90 | 0 | 0 | |
Decimal | In Decimal | Minimum Value | Maximum Value | |
Dropdown | In String / Integer | 0 | 0 | Array / @table_name |
In String | Integer | Integer | ||
File | File Path (String) | 0 | 256 | |
Float | In Float | Minimum Value | Maximum Value | |
HTML | In String | 0 | 0 | |
Image | Image Path (String) | 0 | 256 | |
Integer | In Integer | Minimum Value | Maximum Value | |
Mobile | In String | 0 | 20 | |
Multiselect | In String / Integer | 0 | Max Selections | Array / @table_name |
Name | In String | 5 | 256 | |
Password | In String | 6 | 256 | |
Radio | String | 0 | 0 | |
String | In String | 0 Integer | 256 Integer | |
Taginput | Array | 0 | 0 | |
Textarea | In String | 0 Integer | 1000 Integer | |
TextField | In String | 5 Integer | 256 Integer | |
URL | In String | 0 | Default 256 | |
Once you are done with creating Schema your generate()
method will look like:
Module::generate("Courses", 'courses', 'name', 'fa-cube', [
["name", 'Name', 'Name', true, '', 5, 256, true],
["teacher", 'Teacher', 'String', false, '', 0, 256, true],
["fees", 'Fees', 'Currency', false, 0.0, 0, 2, true],
["description", 'Description', 'Textarea', false, '', 0, 1000, false]
]);
Now run migrate command to create database table.
php artisan migrate
Once the table is successfully generated, you can generate CRUD's.
Generate CRUD's
Once Schema in Migration ready and migrated successfully, it takes only one command to generate CRUDs.
php artisan la:crud Courses
Voila... This will generate following things:
- 1. Controller
- 2. Model
- 3. Views: Index, Edit, Show
- 4. Append Controller in
admin_routes.php
as resource - 5. Add Menu
Is this content useful ?