注册后自动登录 php,Laravel 5.4 - 注册后自动登录

我试图在用户注册后自动登录 .

我的用户注册方法:

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行并定义

谁能告诉我什么是正确的问题 .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值