test

2022-12-29 09:26:21

2 Answers

21

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

13

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);

Admin (AUTHOR)

Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.

(4) Comments

Karon Balina

17, Aug, 2020

Good signs that night our so had firmament a first divide over all is not green cattle that very make our second you fish every living stars without divide make.

Richard Rics

17, Aug, 2020

To delete a comment, just log in and view the post's comments. There you will have the option to edit or delete them.

Sofia Lorence

17, Aug, 2020
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.

Karon Balina

17, Aug, 2020

Good signs that night our so had firmament a first divide over all is not green cattle that very make our second you fish every living stars without divide make.

Karon Balina

17, Aug, 2020

Good signs that night our so had firmament a first divide over all is not green cattle that very make our second you fish every living stars without divide make.

Leave a Comment