I'm trying to automatically login after the user registers.
My user registration method:
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)
]);
}
My User_entity Model:
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:
ErrorException in SessionGuard.php line 407: Argument 1 passed to Illuminate\Auth\SessionGuard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\User_entity given, called in /home/ali/www/brandmashhoor/vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php on line 392 and defined
Can anyone tell me what is the correct problem.
via Ali Hesari