Applying a policy to a resource controller

I have a resource CRUDdefined through Route::resource('User', 'UserController').

Since it is possible to generate CRUDGates and Policies, is there a way to apply such a Gate / Policy so that the corresponding gate / policy is applied to a specific route?

I think this would be an elegant way, since my policies would fit my routes. I am looking for a method like applyPolicy or something simliar:

Route::resource('User', 'UserController')->applyPolicy()

Otherwise, I would have to add every policy to every action that doesn't seem so elegant.

+6
source share
1 answer

Take a look at the method authorizeResource(Model::class).

:

public function __construct()
{
    $this->authorizeResource(Task::class);
}
+5

All Articles