我试图在用户注册后自动登录 .
我的用户注册方法:
public function register_user(Request $request)
{
if (!$request->ajax()) return false;
$form_rule = [
'email' => 'required|email|max:255|unique:tdshop_user_entity',
'password' => 'required|min:6',
];
$validator = Validator::make($request->all(), $form_rule);
$status = $validator->fails();
$form_errors = [];
foreach($form_rule as $field=>$rules){
$form_errors[$field] = $validator->errors()->first($field);
}
if(!$validator->fails()){
$user = User_entity::create([
'email' => $request['email'],
'password' => bcrypt($request['password']),
]);
Auth::loginUsingId($user->user_id);
}
return json_encode([
'status' => ($status)? 'fail' : 'success',
'result' => json_encode($form_errors)
]);
}
我的User_entity模型:
namespace App;
//use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Zizaco\Entrust\Traits\EntrustUserTrait;
use Eloquent;
class User_entity extends Eloquent
{
use Notifiable;
use EntrustUserTrait;
protected $table = 'tdshop_user_entity';
protected $primaryKey = 'user_id';
protected $fillable = ['email','password','status'];
protected $hidden = ['password', 'remember_token'];
public function Attribute_set()
{
return $this->hasOne('App\Attribute_set');
}
public function Attribute_entity()
{
return $this->hasMany('App\Attribute_entity');
}
public function User_address_entity()
{
return $this->hasMany('App\User_address_entity');
}
}
User registration is successful and is recorded in the database. But to login following error is displayed:
SessionGuard.php第407行中的ErrorException:传递给Illuminate \ Auth \ SessionGuard :: login()的参数1必须是Illuminate \ Contracts \ Auth \ Authenticatable的实例,App / User_entity的实例,在/ home / ali /中调用www / brandmashhoor / vendor / laravel / framework / src / Illuminate / Auth / SessionGuard.php在第392行并定义
谁能告诉我什么是正确的问题 .