Laravel Redirect Intended没有做任何事

我目前有一个身份验证功能,我在从Vue组件登录时击中。现在它会记录用户,但不会从控制器发生重定向。我不确定是否使用Vue组件导致了这一点。如果有的话,也许我可以在回复中返回预期的网址?在我login.vue组件Laravel Redirect Intended没有做任何事

public function authenticate(Request $request) 

{

//Validate the login and log errors if any

$this->validate($request, [

'email' => 'required',

'password' => 'required',

]);

//if they have stuff posted get it

$email = $request->get('email');

$password = $request->get('password');

//See if they are actually a user

if (Auth::attempt(['email' => $email, 'password' => $password])) {

return redirect()->intended('/dashboard');

} else {

return response()->json([

'response' => 'error',

'error' => 'Email or Password not correct.',

]);

}

}

登录方法:

login(){ 

this.isLoading = true;

this.form.post('/login')

.then(data => {

this.isLoading = false

if(data.response == 'success'){

//Maybe get a url in the response and redirect here??

} else {

this.serverError= data.error

}

})

.catch(error => {

this.isLoading = false

})

}

使用Laravel 5.4

回答:

,而不是使用方法的目的,为什么不使用redirect()->route()呢?

或者您正在等待URL响应。您不应该使用redirect()方法。

对于您给定的代码,您可能需要考虑这一点。

if (Auth::attempt(['email' => $email, 'password' => $password])) { 

return response()->json([

'response' => 'success',

'url' => Session::get('url.intended', route('route_of_your_dashboard'))

]);

} else {

return response()->json([

'response' => 'error',

'error' => 'Email or Password not correct.',

]);

}

回答:

对于任何人都希望:

在我的身份验证功能:

if (Auth::attempt(['email' => $email, 'password' => $password])) { 

return response()->json([

'response' => 'success',

'url' => Session::get('url.intended', url('/'))

]);

} else {

return response()->json([

'response' => 'error',

'error' => 'Email or Password not correct.',

]);

}

在我VUE组件登录方法从vuejs

if(data.response == 'success'){ 

//console.log(data);

window.location.href = data.url

} else {

this.serverError= data.error

}

以上是 Laravel Redirect Intended没有做任何事 的全部内容, 来源链接: utcz.com/qa/257573.html

回到顶部