您好,我在我的项目中使用 laravel、mongoDB 和 AdminLTE 模板。对于我正在使用的 mongoDB jenssegers/laravel-mongodb
。但是现在我在 laravel 控制器中创建登录身份验证时遇到错误,这是我在 AuthController.php 中的代码
public function postLogin(Request $request)
{
$authUser = User::where('email', '=', $request->email)->first();
if (isset($authUser)) {
if (Auth::attempt(['email' => $request->email, 'password' => $request->password])) {
echo "success";exit;
} else {
echo "fail";exit;
}
} else {
echo "fail";exit;
}
在 User.php 代码中
<?php
namespace App;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
use DB;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\Authenticable as AuthenticableTrait;
class User extends Eloquent implements Authenticatable
{
protected $connection = 'mongodb';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
}
在 User.php 中,如果我只使用 Eloquent 就像class User extends Eloquent
这样得到这个错误
Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\User given, called in /var/www/html/cams_alphaV1/vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php on line 378 and defined
如果我class User extends Eloquent implements Authenticatable
这样使用得到这个错误
Class App\User contains 6 abstract methods and must therefore be declared abstract or implement the remaining methods (Illuminate\Contracts\Auth\Authenticatable::getAuthIdentifierName, Illuminate\Contracts\Auth\Authenticatable::getAuthIdentifier, Illuminate\Contracts\Auth\Authenticatable::getAuthPassword, ...)
请帮助我,我完全被卡住了。