我目前有一个身份验证功能,我在从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
重定向。不从laravel – C2486
从Laravel重定向RESTful API没有太大意义,因为我看到它。我会返回用户实例或类似的东西,并从前端进行重定向。 – Camilo
我刚刚发布了适合我的答案。我只是将预期的URL返回到我的前端,并让它处理它。谢谢@ user2486 – Packy