Laravel5.1 权限管理

准备

如果框架是由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:

你可能感兴趣的:(Laravel5.1 权限管理)