Laravel 在主页中进行登录验证后,如何重定向用户?
在LoginController.php中 我想将用户重定向到主页。但在验证用户身份后,它总是显示空白页Laravel 在主页中进行登录验证后,如何重定向用户?,laravel,redirect,routing,laravel-5.3,Laravel,Redirect,Routing,Laravel 5.3,在LoginController.php中 我想将用户重定向到主页。但在验证用户身份后,它总是显示空白页 公共函数验证器($data,$request) { $email=$data['email']; $check=User::where('email','=',$email)->first(); //如果未找到,则表示我们需要注册用户 如果($check!=null){ //已通过身份验证。。。。。 $id=intval($check->id); Auth::loginUsingId($id
公共函数验证器($data,$request)
{
$email=$data['email'];
$check=User::where('email','=',$email)->first();
//如果未找到,则表示我们需要注册用户
如果($check!=null){
//已通过身份验证。。。。。
$id=intval($check->id);
Auth::loginUsingId($id,true);
//echo'setTimeout(function(){window.history.go(-1);},3000);';
//echo'location.href=“/”;
return redirect()->guest(路线('home');
}
更改返回重定向()->来宾(路线('home');
到
return redirect('home');
或
return redirect()->路由('home');
并确保您的home.blade.php
中有一些数据,否则它将显示空白页。您应该编写此代码
public function authenticater($data,$request)
{
$email=$data['email'];
$check=User::where('email', '=',$email)->first();
//if not found means we need to register the user
if ($check != null) {
// Authentication passed.....
$id=intval($check->id);
Auth::loginUsingId($id,true);
//echo '<html><script>setTimeout(function(){ window.history.go(-1); }, 3000);</script></html>';
//echo '<html><script>location.href="/";</script></html>';
return redirect()->route('profile');
}
公共函数验证器($data,$request)
{
$email=$data['email'];
$check=User::where('email','=',$email)->first();
//如果未找到,则表示我们需要注册用户
如果($check!=null){
//已通过身份验证。。。。。
$id=intval($check->id);
Auth::loginUsingId($id,true);
//echo'setTimeout(function(){window.history.go(-1);},3000);';
//echo'location.href=“/”;
return redirect()->route('profile');
}
这将解决您的问题解决它,
我的错误是:我从控制器的另一个方法调用了authenticator()。因此,控件将转到调用方方法。
$this->authenticater($data,$request);
return redirect('/home');
解决了
安威,我都试过了。还是谢谢你@Jahid26和@Iftikhar uddin:)
$this->authenticater($data,$request);
return redirect('/home');