LoginSignup
98
124

More than 3 years have passed since last update.

【Laravel】わりとよく使うArtisanコマンド集

Last updated at Posted at 2018-08-20

Laravelでよく使うArtisanコマンド一覧

リーダブルにちゃんと載っているし、helpでも一覧が表示されますが、
さっとコピーして使えるように自分的によく使うコマンドをまとめておきます。
(※Lumenでは一部のコマンドしか使えないようですので要注意)

make:migration系(DB関連)

テーブルの作成

php artisan make:migration create_users_table --create=users

オプション
--create=users・・・テーブル名

テーブル構造を変更する場合

php artisan make:migration rename_birth_to_birthdate_on_contacts_table --table=contacts

オプション
--table=contacts・・・テーブル名

migrate系(DB関連)

テーブルのリフレッシュ

全てリセットしてからマイグレーションを行う

php artisan migrate:refresh

テーブルのロールバック

php artisan migrate:rollback --step=1

オプション
--step=1・・・戻す数

テーブルのリセット

全てリセットする

php artisan migrate:reset

マイグレーションの状態を確認する

php artisan migrate:status

オプション

php artisan migrate:status --env=testing --database=sqlite

--env・・・環境
--database・・・DB

上のコマンドでいうと、テスト用のSQLiteのマイグレーションの状態を確認できます

Seeder系(DB関連)

Seederの生成

php artisan make:seeder UsersTableSeeder

Seederの実行

php artisan db:seed --class=TestSeeder

オプション
--class=TestSeeder・・・クラス名

make:controller

Controllerの生成

 php artisan make:controller UsersController

※別ディレクトリへの生成(例:Adminディレクトリ)

 php artisan make:controller Admin\\UsersController

リソースコントローラー

 php artisan make:controller UsersController  --resource

オプション
--resource

make:model

Modelの生成

php artisan make:model User

make:request

Requestクラスの生成

php artisan make:request UserRequest

認証クイックスタート(スキャフォールディング)

php artisan make:auth

スキャフォールディング・・・足場づくり

ルーティング確認

php artisan route:list

キャッシュクリア系

オートロード

composer dump-autoload

キャッシュのクリア

php artisan cache:clear

設定キャッシュのクリア

php artisan config:clear

ルーティングのキャッシュクリア

php artisan route:clear

Viewのキャッシュクリア

php artisan view:clear

参考URL

おわり

以下もどうぞ

98
124
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
98
124