我已经安装了最新版本的lumen v5.6,并编写了新的用户登录微服务。但当我输入我的登录详细信息并使用
Auth::attempt($credential)
方法进行登录,然后一直收到以下错误
Method Illuminate\\Auth\\RequestGuard::attempt does not exist
下面是我的工作方法
public static function loginUser($credentials) {
if (Auth::attempt($credentials)) {
echo "<pre>";
print_r('ok');
exit;
}
return [];
}
下面是我的用户模型
<?php
namespace App;
use Illuminate\Support\Facades\Auth;
use Illuminate\Auth\Authenticatable;
use Laravel\Lumen\Auth\Authorizable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
class User extends BaseModel implements AuthenticatableContract, AuthorizableContract {
use Authenticatable,
Authorizable;
/**
* modal table
* @var type
*/
protected $table = 'users';
/**
* modal primary key
* @var type
*/
protected $primarykey = 'id';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['full_name', 'username',
'email','password', 'picture'
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [];
public static function saveNewUser($inputs) {
$user = new User($inputs);
if ($user->save()) {
return $user;
}
return [];
}
/**
* login user
* @param type $credentials
* @return type
*/
public static function loginUser($credentials) {
if (Auth::attempt($credentials)) {
echo "<pre>";
print_r('ok');
exit;
}
return [];
}
}
我不知道这有什么问题。我也实现了auth配置方法,但是没能解决这个问题。现在我被困在用户登录过程中。指导正确的方向,并提供任何有用的链接来解决这个问题。
发布于 2018-05-28 18:35:44
将此中间件添加到您的路由中:
Route::get('/users/{user}', 'UserController@show')->middleware('auth:api');
https://stackoverflow.com/questions/50563305
复制相似问题