Faraz Ali Faraz Ali - 1 year ago 182
PHP Question

Laravel Controller Middleware for Resources

I am trying to use a middleware on a resource route.

My Route ->

Route::resource('posts', 'PostController');

My Middleware ->

$user = Auth::user();

if(Auth::check()) {
if($user->is_admin) {
return $next($request);
} else {
return redirect()->route('home');
} else {
return redirect()->route('login');

My Controller Constructor ->


My Goal is to let only administrators destroy the post and not others.

But when I use
php artisan route:list
, the middleware shown are web,auth.

What am I doing wrong here?

Answer Source

You can try it as:



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download