artisanコマンドの make:model
でモデル名を指定してモデルを作成できますが、オプションを指定することでマイグレーションファイルやコントローラーファイルなどを同時に作成することが可能です。
モデル作成コマンド(make:model)
基本(モデルのみ作成)
sail artisan make:model Example
マイグレーションファイル同時作成
sail artisan make:model Example --migration sail artisan make:model Example -m
モデルファクトリー同時作成
sail artisan make:model Example --factory sail artisan make:model Example -f
シーダーファイル同時作成
sail artisan make:model Example --seed sail artisan make:model Example -s
コントローラー同時作成
sail artisan make:model Example --controller sail artisan make:model Example -c
モデルとモデルファクトリー・マイグレーション・シーダー・フォームリクエスト・コントローラー・ポリシー同時作成
sail artisan make:model Example --all sail artisan make:model Example -a
*以下、コマンド実行結果
% sail artisan make:model Example --all INFO Model [app/Models/Example.php] created successfully. INFO Factory [database/factories/ExampleFactory.php] created successfully. INFO Migration [database/migrations/2023_01_20_062219_create_examples_table.php] created successfully. INFO Seeder [database/seeders/ExampleSeeder.php] created successfully. INFO Request [app/Http/Requests/StoreExampleRequest.php] created successfully. INFO Request [app/Http/Requests/UpdateExampleRequest.php] created successfully. INFO Controller [app/Http/Controllers/ExampleController.php] created successfully. INFO Policy [app/Policies/ExamplePolicy.php] created successfully.
ピボットモデル作成
sail artisan make:model Example --pivot sail artisan make:model Example -p
オプション確認
make:model -h
で指定可能なオプションを確認出来ます。
% sail artisan make:model -h Description: Create a new Eloquent model class Usage: make:model [options] [--] <name> Arguments: name The name of the class Options: -a, --all Generate a migration, seeder, factory, policy, resource controller, and form request classes for the model -c, --controller Create a new controller for the model -f, --factory Create a new factory for the model --force Create the class even if the model already exists -m, --migration Create a new migration file for the model --morph-pivot Indicates if the generated model should be a custom polymorphic intermediate table model --policy Create a new policy for the model -s, --seed Create a new seeder for the model -p, --pivot Indicates if the generated model should be a custom intermediate table model -r, --resource Indicates if the generated controller should be a resource controller --api Indicates if the generated controller should be an API resource controller -R, --requests Create new form request classes and use them in the resource controller --test Generate an accompanying PHPUnit test for the Model --pest Generate an accompanying Pest test for the Model -h, --help Display help for the given command. When no command is given display help for the list command -q, --quiet Do not output any message -V, --version Display this application version --ansi|--no-ansi Force (or disable --no-ansi) ANSI output -n, --no-interaction Do not ask any interactive question --env[=ENV] The environment the command should run under -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
動作環境情報
"macOS Ventura" 13.1 "Docker Desktop" 4.15.0 "Laravel Sail" "Laravel Framework" 9.43.0
コメント