我使用Lumen 5.2(Laravel)
我错了: 致命错误:Class' Auth'在第10行的C:\ wamp64 \ www \ project \ app \ Http \ Middleware \ AuthToken.php中找不到
自举/ app.php
$app->routeMiddleware([
'auth' => App\Http\Middleware\AuthToken::class,
]);
中间件/ AuthToken.php
namespace App\Http\Middleware;
use Closure;
use Auth;
class AuthToken
{
public function handle($request, Closure $next)
{
if(Auth::check()){
return $next($request);
}else{
abort(401);
}
}
}
UserController.php
使用Auth;
public function login(Request $request){
if ($request->has('password')) {
$user = User:: where("user_password", "=", $request->input('password'))->first();
if ($user) {
$token=str_random(60);
$user->api_token=$token;
$user->save();
return redirect('admin/dashboard');
}
}
routes.php文件
/* ADMIN */
$app->get('/admin', function () use ($app) {
return $app->make('view')->make('admin.login');
});
$app->group(['prefix' => 'admin', 'middleware' => 'auth'], function () use ($app){
$app->get('dashboard', function () use ($app) {
return $app->make('view')->make('admin.dashboard');
});
});
我如何登录该问题?
编辑:我已经尝试了
$app->routeMiddleware([
'auth' => App\Http\Middleware\Authenticate::class,
]);
我只是未经授权。
答案 0 :(得分:1)
在Middleware/AuthToken.php
导入Auth
类,如下所示:
use Illuminate\Support\Facades\Auth;
您想要的是使用Auth Facade
,因此您需要导入它。
答案 1 :(得分:0)