artisanコマンド

2019/08/07

バージョン


$ php artisan -V
$ php artisan --version
Laravel Framework 5.8.30

ヘルプ


$ php artisan help {Word}

make:model の Help


$ php artisan help make:model
Description:
  Create a new Eloquent model class
Usage:
  make:model [options] [--] 
Arguments:
  name                  The name of the class
Options:
  -a, --all             Generate a migration, 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
....

artisan サーバ

デフォルト


$ php artisan serve

Host, Port指定


$ php artisan serve --host=192.168.11.56 --port=8000

ファイル生成


php artisan meke:{Type} {File Name} --{Option}

Type


make:auth                   
make:channel                
make:command                
make:controller             
make:event                  
make:exception              
make:factory                
make:job                    
make:listener               
make:mail                   
make:middleware             
make:migration              
make:model                  
make:notification           
make:observer               
make:policy                 
make:provider               
make:request                
make:resource               
make:rule                   
make:seeder                 
make:test

Option


--controller
--resource
--factory
--migration
--all

CRUD Controller生成


$ php artisan make:controller {Controller Name} --resource

CRUD Controller, Model生成


$ php artisan make:controller {Controller Name} --resource --model=Topic

API Controller


$ php artisan make:controller {Controller Name} --api

Model生成


$ php artisan make:model {Model Name}

Model生成


$ php artisan make:model {Model Name} --all

Factory、Migrationファイルが生成


database/factories/{Model Name}.php
database/migrations/{Model Name}.php

Route一覧


$ php artisan route:list
+--------+----------+----------+------+---------+--------------+
| Domain | Method   | URI      | Name | Action  | Middleware   |
+--------+----------+----------+------+---------+--------------+
|        | GET|HEAD | /        |      | Closure | web          |
|        | GET|HEAD | api/user |      | Closure | api,auth:api |
+--------+----------+----------+------+---------+--------------+

エラーテンプレートの作成

以下のコマンドで、resources/views/errors/ にエラー用のbladeファイルが作成される


$ php artisan vendor:publish --tag=laravel-errors