【发布时间】:2016-09-16 08:07:18
【问题描述】:
您好,我在我的项目中使用 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 中,如果我只使用像 class User extends Eloquent 这样的 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, ...)
请帮帮我,我完全被卡住了。
【问题讨论】:
-
我遇到同样的错误。请帮助stackoverflow.com/questions/62078758/…
标签: laravel-5 jenssegers-mongodb