Laravel 5.1権限管理

2231 ワード

の準備を
フレームワークが5.0からアップグレードされた場合、権限管理機能を使用するには少し変更する必要があります.公式アップグレードガイドから
Create The Policies Directory
First, create an empty app/Policies directory within your application.
Create/Register The AuthServiceProvider & Gate Facade
Create a AuthServiceProvider within your app/Providers directory. You may copy the contents of the default provider from GitHub. Remember to change the provider's namespace if your application is using a custom namespace. After creating the provider, be sure to register it in your app.php configuration file's providers array.
Also, you should register the Gate facade in your app.php configuration file's aliases array:
'Gate' => Illuminate\Support\Facades\Gate::class,
Update The User Model
Secondly, use the Illuminate\Foundation\Auth\Access\Authorizable trait and Illuminate\Contracts\Auth\Access\Authorizable contract on your App\User model:

Update The Base Controller
Next, update your base App\Http\Controllers\Controller controller to use the Illuminate\Foundation\Auth\Access\AuthorizesRequests trait: