我正在尝试在TeamController上应用策略:
TeamPolicy是:
public function before(User $user, $ability)
{
if ($user->isSuperAdmin()) {
return true;
}
return null;
}
public function create(User $user, Tournament $tournament)
{
return $user->isOwner($tournament);
}
在我的控制器中,我这样称呼它:
public function create(Tournament $tournament)
{
$team = new Team;
if (Auth::user()->cannot('create', $team)) {
throw new UnauthorizedException();
}
}
我在两个函数中都有,但从未被调用过。
知道什么是错的???
答案 0 :(得分:1)
您是否在AuthServiceProvider中注册了您的政策,如下所示:https://laravel.com/docs/5.2/authorization#creating-policies?