sanjayacloud
1 week ago
108
16
Laravel

Auth middleware error.

Posted 1 week ago by sanjayacloud

Hi Everyone,

I am trying to make auth middleware call "Admin" And it registered on http kernal. But when i add it into my controller in constructor. I got below error.

Error: "Class admin does not exist"

My constructor

public function __construct()
    {
        $this->middleware(['auth','admin']);
    }

And below my middleware

<?php

namespace App\Http\Middleware;

use Closure;

class Admin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if(auth()->user()->role == 5){
            $response = $next($request);
            $response->header('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0')->header('Pragma', 'no-cache')->header('Expires', 'Sat, 26 Jul 1997 05:00:00 GMT');
            return $response;
        }
        return redirect('/admin/login')->with('login-msg','You have not admin access');
    }
}

Anyone can help me to resolve this error?

Please sign in or create an account to participate in this conversation.