我应该如何在Laravel 5.6中实现授权

时间:2018-05-12 19:53:52

标签: php laravel laravel-5 model laravel-authorization

我成功地在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方法?

0 个答案:

没有答案