shibuyakosuke/laravel-crud-command

Generate CRUD files for laravel.

1.0.0 2020-10-29 11:45 UTC

This package is auto-updated.

Last update: 2024-04-12 13:39:41 UTC


README

日本語

Get the schema from the pre-created database and use the artisan command to batch output the files needed for CRUD.

Feature

  1. Generate a file for translation from MySQL table comment and column comment.
    • resourcees/lang/{locale}/tables.php
    • resourcees/lang/{locale}/columns.php
  2. Create validation rule from MySQL table definition.
    • rules/{model}.php
  3. Model creation
    • A property is automatically generated from the table column.
    • Output belongsTo, hasMany, belongsToMany methods from the foreign key constraint.
  4. Controller creation
    • Output all methods required for CRUD.
  5. Global scope creation
    • Create one global scope class for each model.
  6. Form request class creation
    • The rules are automatically output from the table definition.
  7. View composer creation
    • Automatically generate the logic that passes the form part to the view from the foreign key definition.
  8. View creation
    • Lists, details, new creations and updates are automatically generated.
  9. Bread crumb list creation
    • A breadcrumb trail is automatically output to the file generated by CRUD.
  10. 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.

Install

composer require shibuyakosuke/laravel-crud-command

Setup

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');
});
2. Execute migration
php artisan migrate
3. Edit config/app.php to set language
'locale' => 'ja',
4. Output resource
php artisan crud:setup
5. Output all CRUD files
php artisan make:crud users
Option
  • --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.

Other commands

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