shibuyakosuke / laravel-crud-command
Generate CRUD files for laravel.
1.0.0
2020-10-29 11:45 UTC
Requires
- php: ^7.2.5 | ^7.3 | ^7.4
- barryvdh/laravel-dompdf: ^0.8.6
- diplodocker/comments-loader: ^0.0.2
- laravel/framework: ^6.0 | ^7.0 | ^8.0
- laravelcollective/html: ^6.1 | ^6.2
- maatwebsite/excel: ^3.1
- shibuyakosuke/laravel-crud-breadcrumbs: ^1.0.0
- shibuyakosuke/laravel-database-validation: ^1.2.0
- shibuyakosuke/laravel-form-extend: ^1.0
- shibuyakosuke/laravel-model-replacement: ^1.1.1
- watson/rememberable: ^3.0 | ^4.0 | ^5.0
Requires (Dev)
- mockery/mockery: ^1.3 | ^1.4
- orchestra/testbench: ^5.0 | ^6.0
- phpunit/phpunit: ^8.0 | ^9.0
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2025-03-12 15:47:18 UTC
README
Get the schema from the pre-created database and use the artisan command to batch output the files needed for CRUD.
Feature
- 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.
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