It seems like the previous version of Laravel that you could pass the class name as a string to authorize: $this->authorize('store', Event::class);, but this now returns Type error: Argument 2 passed to App\Policies\EventPolicy::store() must be an instance of App\Event, string given. Is it possible to set a policy on index, create, and store in Laravel 5.2? I'm trying to do this to authorize whether a user can actually create a new event or not.
/**
* Determine if the given user can create an event based on users only
* being allowed to create a single event each.
*
* @param User $user
*
* @return bool
*/
public function store(User $user)
{
return $user->events()->isEmpty();
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire