我收到错误:
ReflectionException在Container.php第572行:类请求没有存在
查看我的routes.php页面的代码。
$app->get('/records', ['middleware' => 'auth', function (Request $request) {
$user = Auth::user();
return json_encode($user);
}]);
我遵循了Lumen网站上的文档。用取消相关行的注释,bootstrap/app.php
下面是我的中间件代码:<?php
namespace App'Http'Middleware;
use Closure;
use Illuminate'Contracts'Auth'Factory as Auth;
class Authenticate
{
protected $auth;
public function __construct(Auth $auth)
{
$this->auth = $auth;
}
public function handle($request, Closure $next, $guard = null)
{
if ($this->auth->guard($guard)->guest()) {
return response()->json('unauthorized', 401);
}
return $next($request);
}
}
和AuthServiceProvider文件:
<?php
namespace App'Providers;
use App'User;
use Illuminate'Support'Facades'Gate;
use Illuminate'Support'ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
public function register()
{
}
public function boot()
{
$this->app['auth']->viaRequest('api', function ($request) {
if ($request->header('Authorization')) {
$user = User:: where('api_token', '=', substr($request->header('Authorization'), 6))->first();
return $user;
}
return null;
});
}
}
add this line
use Illuminate'Http'Request;