Generator generates all the CRUD code based on the migrated table structure. It follows convention over configuration principle, so it is very simple to use for a typical use case. So instead of using a god-powerful tool that can do anything, with the generator you quickly scaffold all the common stuff, so you can focus on all the details each module differs from each other.
Generator supports these Illuminate\Database\Schema\Blueprint
types in your migrations:
string
text
date
datetime
time
boolean
jsonb
{primary} You can use any other type in your migration, but it will be treated exactly like it is a
string
type.
{warning} Note that
jsonb
type has special meaning.
Generator creates these new files:
On addition it also:
Generator automatically generates the create and edit forms for a specified model reflecting all its attributes.
Generator supports these form elements:
string
or any other type not specified in this list)text
)text
, body
, description
)date
)datetime
)time
)number
)jsonb
)boolean
)Primary key and other system attributes (i.e. created_at
, updated_at
, ...) are excluded from the forms.
Generator automatically generates the CRUD listing with search ability. Listing includes all the attributes except:
text
typejsonb
type when the attributes name is one of: perex
, text
or body
password
attributecreated_at
, updated_at
, ...)If attribute of boolean
type has a name one of: enabled
, activated
or is_published
, then it will be automatically generated as a switch element.
All the text
and string
attributes are by default searchable.
For security reasons generator generates a routes that are protected with 4 different abilities defined in the generated request classes:
admin.model-name.index
admin.model-name.create
admin.model-name.edit
admin.model-name.destroy
Craftable automatically generates also migration introducing these abilities as migrations and assign them to the default Administrator role.
Generator generates validation rules for store and update request classes. Attribute types are reflecting standard Laravel's validation rules.
Not setting nullable
on attribute makes the attribute required
on store request and sometimes
on update request.
Attribute named email
gets a proper email
validation rule.
Generator provides --with-export
option that provides the ability to export data as .xlsx
. Generator generates a [ModelName]Export
class within App/Export
directory that provides several options (i.e. attributes to export, formatting, etc.). For more information see the documentation of Laravel Excel.
If you specify columns as shown below in your migration, Generator will generate whole CRUD including user-detail-tooltip component in your listing.
$table->unsignedInteger('created_by_admin_user_id');
$table->foreign('created_by_admin_user_id')->references('id')->on('admin_users')->onDelete('cascade');
$table->unsignedInteger('updated_by_admin_user_id');
$table->foreign('updated_by_admin_user_id')->references('id')->on('admin_users')->onDelete('cascade');
If your migration contains published_at
column as shown below, Generator will generate whole CRUD including ability to publish instance of your model in listing. Generator will also generate user friendly two col form.
$table->date('published_at')->nullable();
By default Generator will generate bulk delete action in listing. If you want to disable this feature just use --without-bulk
option.
Generator provides --seed
option that enables you to populate the table with fake data using just generated factory.
Unfortunately, generator does not provide an option to add new attribute once the CRUD was generated. But you can always regenerate entire CRUD using --force
option:
php artisan admin:generate --force posts
{warning} We strongly recommend to backup your code before forced regeneration.
Behind the scenes generator provides several commands, the building blocks of the generator:
admin:generate:model
Generate a model classadmin:generate:controller
Generate a controller classadmin:generate:index
Generate an index view templateadmin:generate:form
Generate create and edit view templatesadmin:generate:factory
Append a new factoryadmin:generate:routes
Append admin routes into a web routes fileadmin:generate:request:index
Generate an Index request classadmin:generate:request:store
Generate a Store request classadmin:generate:request:update
Generate an Update request classadmin:generate:request:destroy
Generate a Destroy request classadmin:generate:permissions
Generate a default permissions migrationTypically, you don't want to use any of these commands, you just want to generate the whole CRUD interface with all the stuff using:
admin:generate
Scaffold complete CRUD admin interfacewhich basically runs all the commands above in one run.