Pass user id in laravel after logged in

∥☆過路亽.° 提交于 2019-12-12 04:44:06

问题


I would like to pass / submit the user_id of the currently logged on user. How will I do it in laravel 5.2? Please need help

I am not sure on my code on how will I use Auth:user() blah blah. Need help with this. I am new to this.


回答1:


You can use the login functionality like this and pass the datas to the required pages as per your wish.

public function Dologin()
{
// create our user data for the authentication
$userdata = array(
'email'     => Input::get('email'),
'password'  => Input::get('password'),
);
if (Auth::attempt($userdata)) 
{
$user_id=Auth::user()->user_id;// user_id it will change as per the users table in your project.
return redirect('index');
}
else
{
}
}

Make sure you save your password using bcrypt method and for that alone the Auth::check() and Auth::user() will work.



来源:https://stackoverflow.com/questions/39179773/pass-user-id-in-laravel-after-logged-in

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!