我需要帮助解决一个我自己无法解决的问题。 我正在使用Laravel 5.1,当我尝试启用Authenticate Middleware时,我收到此错误。
ErrorException in Manager.php line 137:
call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Auth\Guard' does not have a method 'handle'
我有中间件,因为它默认使用Laravel,也是kernel.php,都看起来像这样
<?php
namespace Imuva\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Guard;
class Authenticate {
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;
/**
* Create a new filter instance.
*
* @param Guard $auth
* @return void
*/
public function __construct(Guard $auth) {
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next) {
if ($this->auth->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('auth/login');
}
}
return $next($request);
}
}
内核:
protected $routeMiddleware = [
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \Imuva\Http\Middleware\RedirectIfAuthenticated::class,
'auth' => \Imuva\Http\Middleware\Authenticate::class,
];
我从这里开始使用它:
class HomeController extends Controller {
public function __construct() {
$this->middleware('auth', ['only' => 'admin']);
}
我根本不知道会发生什么。感谢您的阅读
答案 0 :(得分:0)
我认为你混淆了你发现的有关中间件的所有内容。