How to make auto login after registration in laravel

0 votes

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 help me out?

Nov 2, 2020 in Laravel by kartik
• 37,520 points
5,339 views

1 answer to this question.

0 votes

Hello,

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!

answered Nov 2, 2020 by Niroj
• 82,880 points

Related Questions In Laravel

0 votes
1 answer

How to Make Laravel Eloquent “IN” Query?

Hello @kartik, Here is how you do in ...READ MORE

answered Aug 4, 2020 in Laravel by Niroj
• 82,880 points
989 views
0 votes
1 answer

How to redirect to login if user is not authenticated in laravel?

Hello @kartik, Use middleware for this purpose and ...READ MORE

answered Oct 28, 2020 in Laravel by Niroj
• 82,880 points
8,786 views
0 votes
1 answer

How to redirect to Login if user not logged in Laravel?

Hello @kartik, You can use it in middleware. ...READ MORE

answered Dec 4, 2020 in Laravel by Niroj
• 82,880 points
27,314 views
0 votes
1 answer

How to make a new page with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
12,997 views
0 votes
1 answer

How can we Create Multiple Where Clause Query Using Laravel Eloquent?

Hii, You can use Conditions using Array: $users = User::where([ ...READ MORE

answered Mar 30, 2020 in Laravel by Niroj
• 82,880 points
16,719 views
0 votes
1 answer

How to send email using php?

Hello @kartik 1.) Download PHPMailer, open the zip file ...READ MORE

answered Apr 1, 2020 in PHP by Niroj
• 82,880 points
1,335 views
0 votes
1 answer

Where to register Facades & Service Providers in Lumen?

Hello, To register a facade with an alias, ...READ MORE

answered Apr 6, 2020 in Laravel by Niroj
• 82,880 points
4,455 views
0 votes
1 answer

How can I update NodeJS and NPM to the next versions?

Hello @kartik, First check your NPM version npm -v 1).Update ...READ MORE

answered May 5, 2020 in Java-Script by Niroj
• 82,880 points
1,007 views
0 votes
1 answer

How to make a constant and use globally in laravel?

Hii, You can create a constants.php page in config folder ...READ MORE

answered Mar 24, 2020 in Laravel by Niroj
• 82,880 points
4,037 views
0 votes
1 answer

Error:login in Laravel. How to solve?

Hey, First check if your model login has a field password in ...READ MORE

answered Mar 26, 2020 in Laravel by Niroj
• 82,880 points
7,688 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP