Laravel 個人リファレンス
目次
コマンド
基本コマンド
$ php artisan #コマンド確認
$ php artisan -V #バージョン確認
$ php artisan serve #サーバー起動
ルーティング
$ php artisan route:list #ルーティング確認
$ php artisan route:cache #キャッシュ作成
$ php artisan route:clear #キャッシュ削除
コントローラー・モデル等
$ php artisan make:controller HogeController
$ php artisan make:model Foo
$ php artisan make:model Foo -m
$ php artisan make:middleware xxxx
$ php artisan make:provider xxxxProvider
$ php artisan make:request xxxxRequest
$ php artisan make:test xxxxTest
$ php artisan make:factory xxxxTest
$ php artisan make:mail EmailVerification
DB関係
$ php artisan make:migration create_foo_table
$ php artisan make:migration add_foo_table --table="users"
# テーブル指定
$ php aritsan make:migration
$ php artisan migrate
$ php artisan migrate:rollback
$ php artisan migrate:reset
$ php artisan migrate:status
$ php artisan migrate:refresh
# 全データ消える
$ php artisan migrate:fresh
$ php artisan make:seeder UsersTableSeeder
$ php artisan db:seed
$ php artisan db:seed --class=UserTableSeeder
$ composer dump-autoload
ユーティリティ
$ php artisan down | php artisan up
$ php artisan config:cache
$ php artisan route:clear
$ php artisan cache:clear
$ php artisan optimize
$ php artisan tinker
$ php artisan storage:link
データベース表示
$ sqlite3 test.sqlite3
$ .table
$ .schema <table_name>
フレームワークのクラス
Route, Routerクラス
// 下記でprivateで定義されている$routerを取得できる。
// $routerはクラスRouteインスタンスなのでRoute内のメソッドが使用できる
Route::current();
// @return array:[middleware, uses, controller, as, namespace, prefix, where]
var_dump(Route::current()->getAction());
// @return string (コントローラー@アクション)
var_dump(Route::current()->getActionName());
// @return string (routeに定義されたName)
var_dump(Route::current()->getName());
// @return string (routeに定義されたPrefix)
var_dump(Route::current()->getPrefix());
RouteCollectionクラス
// Route::getRoutes()はroute/web.phpに設定しているルーティングを取得することができる。
// 取得した値はRouteCollectionクラスになる。
Route::getRoutes()->getRoutesByName()
Storageクラス
$visibility = Storage::disk('s3')->getVisibility($request->path());