类App\Http\UserMiddleware不存在
<?php
namespace App\Http\Middleware;
use Closure;
Use Auth;
class UserMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if(auth::check() && Auth::user()->role->id == 2){
return $next($request);
}
else {
return redirect()->route('login');
}
}
}
3条答案
按热度按时间tag5nh1u1#
如果文件保存在App\Http而不是App\Http\Middleware中,则名称空间声明是错误的,并将引发异常
bvhaajcl2#
用这个
r9f1avp53#
将内核文件中的中间件更改为如下所示