3
3
3ksploit2019-12-10 13:34:54
Laravel
3ksploit, 2019-12-10 13:34:54

How to use resource for different user roles?

There is a resource, inside the middleware (role check):

Route::group(['middleware' => ['role:creator,viewer']], function() { 
    Route::resource('passports', 'PassportsController');
});

How can I make creator have all resource methods and viewer only ' index ' and ' show ' ?
I tried to define resource 2 times:
Route::resource('passports', 'PassportsController', [
    'middleware' => 'role:creator'
]);
Route::resource('passports', 'PassportsController', [
    'middleware' => 'role:viewer'
])->only(['index', 'show']);

But it does not work, especially since defining a resource 2 times is not the best solution.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2019-12-10
@3ksploit

With the help of policies

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question