我成功地在laravel 5.3中实现了授权。但是在Laravel 5.6 Policy方法中,例如index,view,...并不起作用,Laravel也没有在策略上调用这些方法。为什么?
控制器:
public function index($member)
{
$this->authorize(Time::find($member));
...
}
AuthServiceProvider:
protected $policies = [
User::class => UserPolicy::class,
Time::class => TimePolicy::class,
];
TimePolicy:
public function index(User $user, Time $time)
{
if ($time->member_id == $user->id)
return true;
}
public function view(User $user, Time $time)
{
if ($time->member_id == $user->id) {
return true;
}
}
为什么Laravel 5.6不会调用相关的Policy方法?