当我尝试登录或注册或尝试访问受限制的页面时,此错误显示。如何解决这个错误?
Declaration of AppHttpMiddlewareAuthenticate::handle($request, Closure $next) must be compatible with IlluminateAuthMiddlewareAuthenticate::handle($request, Closure $next, ...$guards)
这是/app/Http/Middleware/Authenticate.php代码:
<?php
namespace AppHttpMiddleware;
use IlluminateAuthMiddlewareAuthenticate as Middleware;
use Closure;
use Auth;
class Authenticate extends Middleware
{
public function handle($request, Closure $next)
{
if (Auth::check()) {
return $next($request);
}
return redirect()->route('user.login');
}
}
原始方法的原型(Middleware::handle()
)是handle($request, Closure $next, ...$guards)
,所以您的方法也必须是这样的。如果你不需要这些$guards
,你可以不使用它们,但它们必须在原型中。
<?php
namespace AppHttpMiddleware;
use IlluminateAuthMiddlewareAuthenticate as Middleware;
use Closure;
use Auth;
class Authenticate extends Middleware
{
public function handle($request, Closure $next, ...$guards)
{
if (Auth::check()) {
return $next($request);
}
return redirect()->route('user.login');
}
}