i am new to laravel and i am trying to make an admin dashboard but in the adminmiddleware file i am having this error with both of my Auth
Undefined type 'App\Http\Middleware\Auth'
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class AdminMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next)
{
if (Auth::check()) {
if (Auth::user()->role_as == '1') {
return $next($request);
} else {
return redirect('/home')->with('status', 'Access denied! as you are not an admin');
}
} else {
return redirect('/home')->with('status', ' pleaselogin first');
}
}
}
CodePudding user response:
either use the Auth facade from the global namespace: \Auth,
or (better) add its FQCN in your use declarations: use Illuminate\Support\Facades\Auth;
CodePudding user response:
add
use Illuminate\Support\Facades\Auth;
before
use Illuminate\Http\Request;