Get the schema from the pre-created database and use the artisan command to batch output the files needed for CRUD.
- Generate a file for translation from MySQL table comment and column comment.
- resourcees/lang/{locale}/tables.php
- resourcees/lang/{locale}/columns.php
- Create validation rule from MySQL table definition.
- rules/{model}.php
- Model creation
- A property is automatically generated from the table column.
- Output belongsTo, hasMany, belongsToMany methods from the foreign key constraint.
- Controller creation
- Output all methods required for CRUD.
- Global scope creation
- Create one global scope class for each model.
- Form request class creation
- The rules are automatically output from the table definition.
- View composer creation
- Automatically generate the logic that passes the form part to the view from the foreign key definition.
- View creation
- Lists, details, new creations and updates are automatically generated.
- Bread crumb list creation
- A breadcrumb trail is automatically output to the file generated by CRUD.
- Template customization
- Depending on the project, you may need to customize the output template. In that case, you can edit the stub as you like.
composer require shibuyakosuke/laravel-crud-command
1. First and foremost, start by creating a migration file. Be sure to set the comment and foreign key as shown in the example.
- Be sure to add a table comment to the table that generates the model.
- Do not comment on many-to-many intermediate tables.
For the table comment function, diplodocker/comments-loader is used.
use Illuminate\Database\Schema\Blueprint;
Schema::create('users', function (Blueprint $table) {
$table->id()->comment('ID');
$table->unsignedBigInteger('role_id')->nullable()->comment('ロールID');
$table->unsignedBigInteger('company_id')->nullable()->comment('会社ID');
$table->string('name')->comment('氏名');
$table->string('email')->unique()->comment('メールアドレス');
$table->timestamp('email_verified_at')->nullable()->comment('メール認証日時');
$table->string('password')->comment('パスワード');
$table->rememberToken()->comment('リメンバートークン');
$table->timestamp('created_at')->nullable()->comment('作成日時');
$table->timestamp('updated_at')->nullable()->comment('更新日時');
$table->softDeletes()->comment('削除日時');
$table->tableComment('ユーザー'); // Table comment helps you to make language files.
// Foreign key helps you to make belongsTo methods, hasMany methods and views .
$table->foreign('role_id')->references('id')->on('roles');
$table->foreign('company_id')->references('id')->on('companies');
});
php artisan migrate
'locale' => 'ja',
php artisan crud:setup
php artisan make:crud users
--force
Even if the file exists, it is overwritten and output.--api
Outputs only the REST controller, not the normal controller.--with-api
Output normal controller and controller for REST. It cannot be specified at the same time as--api
.--sortable
The table sorting function is output.--with-export
The table export function is output.--with-filter
The table filter function is output together.--with-trashed
The table export function is output.
To customize the output file, execute the following command to output multiple product files with the extension .stub in the /stubs directory. Customize the output file.
php artisan stub:publish