2017-03-15 102 views
0

我有这样的功能:重定向到页面不工作?

public function index(Request $request){ 
    $email = $request->email; 
$password = $request->password; 

if (!$email || !$password) {return redirect()->back();} 
if (Auth::attempt(['email' => $email, 'password' => $password])) { 
    // Authentication passed... 
    $this->loggedUser = Auth::user(); 
    if($this->loggedUser){ 
      return redirect('http://localhost:3000/home'); 
    } 

} 
return redirect()->back()->withInput()->withErrorMessage('Uneseni podaci nisu ispravni.'); 

} 

我想要的是,如果他登录到用户重定向,但没有happend。当我打开我的浏览器预览它只是说

Redirecting to http://localhost:3000/home 

但它不重定向我。任何建议?

当我手动输入出现

+0

尝试'重定向(“/家庭”)' –

+0

同样的问题..它只是说redirectin预览,但什么也没有发生 – None

+0

这个方法做工精细的其他重定向? –

回答

0

更改重定向地址:如果你想重定向到一个绝对的URL,你可以试试这个

return redirect('home'); 
+0

再次没有发生,但在预览它说: 重定向到http:// localhost:8000/home。这就是它....在我的浏览器路由是http:// localhost:3000。 – None

0

return redirect(url('http://localhost:8000/home')); 

或者你可以试试这个相对网址:

return redirect('/home')); 

第一个不好,因为如果你的域(http://localhost:8000)是 改变了,那么你所有的链接都需要改变。所以第二个 的做法比较好。

+0

我知道,但对我来说,它不工作......也许是因为即时通讯使用角度 – None

+0

如果您发送AJAX请求,重定向将无法正常工作。你必须使用JavaScript或Angular路由从你的前端重定向 –

+0

所以我可以返回json响应,然后处理角度和设置路由? – None