Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ahmadaiman's avatar

Help on authorizeResource() alternative in Laravel 11

In laravel 10 I can use authorizeResource() if I utilize resource controller via Controller helper but in laravel 11 there is no 'via controller helper' section but replaced by 'via Gate facade'. Does using Gate::authorize('create', Post::class); will achieve the same result as $this->authorizeResource(Post::class, 'create'); ?

thank you so much this

0 likes
3 replies
puklipo's avatar

AuthorizesRequests can be added freely.

use App\Models\Post;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class PostController extends Controller
{
    use AuthorizesRequests;

    public function __construct()
    {
        $this->authorizeResource(Post::class, 'post');
    }
}

You can also add it to app/Http/Controllers/Controller.php

2 likes
elton869's avatar

@puklipo The controller needs to extend from Illuminate\Routing\Controller; to working properly.

3 likes
vincent15000's avatar

In previous Laravel versions, AuthorizesRequests was used automatically in the base Controller class. And the documentation suggested to use $this->authorize() to check the authorizations defined via policies.

But in the last version (11), it's recommended to use Gate::authorize() instead.

Is it exactly the same code executed under the hood ? Or is it different ?

4 likes

Please or to participate in this conversation.