登录后在laravel中传递用户ID

时间:2016-08-27 09:56:03

标签: laravel-5.2

我想传递/提交当前登录用户的Auth:user()。我将如何在laravel 5.2中进行此操作?请帮忙

我不确定我的代码将如何使用{{1}}等等等等。需要帮助。我是新手。

1 个答案:

答案 0 :(得分:0)

  

您可以使用此类登录功能,并根据您的意愿将数据传递到所需的页面。

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()将起作用。