I have encounterd a problem while regiserting user in laravel, $user
suppose to be array which contains all array element while auto login the following code results false. The password save in the database is hash::make('password')
.
$user_id = $this->user_model->addUser($user);
$post = array('password' => $pass_for_auth, 'email' => $email);
var_dump(Auth::attempt($post,true));die;
Can any one tell me what is the correct problem
You can try to login the user through his $user_id
. So your code will be:
$user_id = $this->user_model->addUser($user);
$post = array('password' => $pass_for_auth, 'email' => $email);
Auth::loginUsingId($user_id);
You created the user so it returns an user_id, with the user_id you can login the user.
Hope this works!
More information at: https://laravel.com/docs/5.2/authentication#other-authentication-methods
This would be the standard way to do user registration - you create a new user model instance and pass it to Auth::login() :
// do not forget validation!
$this->validate($request, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
]);
$data = $request->all();
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
Auth::login($user);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With