2014-04-21 233 views
0

当谈到Laravel时,我有点新手,所以我希望有人能帮忙。Laravel - 登录后重定向

我使用Laravel附带的标准身份验证和登录内容,所以没有什么奇怪的事情发生,但我想要做的是检查数据库,看看是否有几个字段完成(名称,地址,邮编)。 ...如果是,那么用户将被重定向到仪表板,但如果它们不是,用户将被重定向到配置文件页面以填写其余的信息。

即时猜测我应该把东西在我的routes.php文件文件中的

Route::post('login', function 

一部分,但我如何检查该字段?

任何帮助将不胜感激。

干杯,

回答

1

一旦你验证使用Auth::check你就可以抓住身份验证的用户与Auth::user用户。

if (Auth::attempt($credentials)) 
{ 
    $user = Auth::user(); 

    if ($user->email == '' || $user->address == '') 
    { 
     return Redirect::to('user/profile'); 
    } 

    return Redirect::to('home'); 
} 

你只需要检查用户的字段,确保它们在那里。如果他们不是,那么他们重定向到个人资料页面。如果他们将他们重定向到主页或其他地方。

+0

完美,谢谢你......我不知道有关验证::用户()的事情,那使事情变得更容易。干杯 – BigJobbies

0

您可以使用此代码

if (Auth::guest()) 
{ 
    //user is not authenticated or logged in; 
    return Redirect::to('login'); 
}else{ 
    //user is authenticated and logged in; 
    return Redirect::to('profile'); 
} 
1

你也可以这样来做

if (Auth::attempt(array('email'=>Input::get('email'), 'password'=>Input::get('password')))) { 
     return Redirect::to('users/dashboard'); 
    } else { 
     return Redirect::to('users/profile'); 
    }