// Gate - простое правило авторизации
Gate::define('update-post', fn(User $user, Post $post) => $user->id === $post->user_id);
// Policy - набор правил для модели
class PostPolicy {
public function update(User $user, Post $post): bool {
return $user->id === $post->user_id;
}
public function delete(User $user, Post $post): bool {
return $user->isAdmin() || $user->id === $post->user_id;
}
}
// Использование
$this->authorize('update', $post);
if ($user->can('delete', $post)) { /* ... */ }
@can('update', $post) ... @endcan