Merhaba,
Daha az kod yazmak için;
Authorizing Resource Controllers
https://laravel.com/docs/5.8/authorization#via-controller-helpers
https://laravel.com/docs/5.8/controllers#resource-controllers
class PostController extends Controller
{
public function __construct()
{
$this->authorizeResource(Post::class, 'post');
}
}
şeklinde kullanılabilir.
Ek metot ve rotalar için;
PostPolicy.php
public function download(User $user, Post $post)
{
return $user->id === $post->user_id ;//vb.
}
PostController.php
public function download(Request $request, Post $post)
{
$this->authorize('download', $post);
// .....
}
gibi kullanıyorum.
Policy/Model değilde Gate olarak tanımlı ise sadece rotada grup ve tekil duruma göre kullanıyorum.
İyi çalışmalar.