
モデル、コントローラ、マイグレーションファイルを一括作成
以下のコマンドを実行することで一括でモデル、コントローラ、マイグレーションファイルを作成することができます。
php artisan make:model 作りたいモデル名 -mc
モデルとマイグレーションファイルのみを作成したい場合には以下を実行することで作成できます。
php artisan make:model 作りたいモデル名 -m
モデルとコントローラのみを作成したい場合には、以下を実行することで作成できます。
php artisan make:model 作りたいモデル名 -c
このようにそれぞれオプションに基づいて作成できるものが変わってきます。
以下は「php artisan make:model -h」の実行結果となります。
それぞれオプションの解説が出力されます。
Options:
-a, --all Generate a migration, seeder, factory, and resource controller 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
-s, --seed Create a new seeder file 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 controller
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable 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
CRUD関数も一緒に作成
中でも便利なのは、「-r」のオプションでCRUDの空の関数があらかじめ記載されたコントローラが作成されます。
<?php
namespace App\Http\Controllers;
use App\todo;
use Illuminate\Http\Request;
class TodoController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param \App\todo $todo
* @return \Illuminate\Http\Response
*/
public function show(todo $todo)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\todo $todo
* @return \Illuminate\Http\Response
*/
public function edit(todo $todo)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\todo $todo
* @return \Illuminate\Http\Response
*/
public function update(Request $request, todo $todo)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\todo $todo
* @return \Illuminate\Http\Response
*/
public function destroy(todo $todo)
{
//
}
}