用户授权Policy
定义策略类
php artisan make:policy <name>
- 定义方法
注册策略类和模型关联
- app > Providers > AuthServiceProvider.php
protected $policies = [ 'AppModel' => 'AppPoliciesModelPolicy', ];
- php中:
$this->authorize('funName', $对象)
if ($user->can('funcName', $对象)){//todo}
- html中:
@can('funName', $对象) //todo @elsecan //todo @endcan