Background Image

Migrations & CRUD's

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

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 []

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"]
Field
Description
1col_name_dbDatabase column name. lowercase, words concatenated by underscore (_)
2LabelLabel of Column e.g. Name, Cost, Is Public
3UI_TypeIt defines type of Column in more General way. Please see table for UI Types.
4Is_UniqueWhether the column has unique values. Value in true / false
5Default_ValDefault value for column.
6min_lengthMinimum Length of value in integer.
7max_lengthMaximum Length of value in integer.
8Is_RequiredIs this mandatory field in Add / Edit forms. Value in true / false
9valuesThis is for MultiSelect, TagInput and Radio Columns.
Create Name / Title Column:
["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)
AddressIn StringIntegerInteger
Checkboxtrue / false00
CurrencyIn DecimalMinimum ValueMaximum Value
Datenow()
2016-06-23
00
Datetimenow()
2016-06-23 14:20:90
00
DecimalIn DecimalMinimum ValueMaximum Value
DropdownIn String / Integer00Array / @table_name
EmailIn StringIntegerInteger
FileFile Path (String)0256
FloatIn FloatMinimum ValueMaximum Value
HTMLIn String00
ImageImage Path (String)0256
IntegerIn IntegerMinimum ValueMaximum Value
MobileIn String020
MultiselectIn String / Integer0Max SelectionsArray / @table_name
NameIn String5256
PasswordIn String6256
RadioString00
StringIn String0 Integer256 Integer
TaginputArray00
TextareaIn String0 Integer1000 Integer
TextFieldIn String5 Integer256 Integer
URLIn String0Default 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.

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 ?

What's Next ?