登录后在laravel中传递用户ID [英] Pass user id in laravel after logged in
本文介绍了登录后在laravel中传递用户ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过/提交当前登录用户的user_id
.我将如何在laravel 5.2中做到这一点?请寻求帮助
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
我不确定我将如何使用Auth:user()
等等.需要帮助.我是新来的.
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.
推荐答案
您可以使用这种登录功能,并根据需要将数据传递到所需页面.
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
{
}
}
确保使用bcrypt方法保存密码,仅此一项,Auth :: check()和Auth :: user()就可以使用.
Make sure you save your password using bcrypt method and for that alone the Auth::check() and Auth::user() will work.
这篇关于登录后在laravel中传递用户ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文