Nicola Nicola - 5 months ago 38
PHP Question

How to redirect to a route in a called function laravel

I am tidying up my code and it makes sense for me to remove the login function outside of my formhandler function. However, when I call the return route line in my called function, it simply returns this route back to the parent controller, which does nothing with it. I want my redirect to be carried out within the called function.

public static function loginFormHandler(){

//some stuff is done

$this->doLogin();
}

public static function doLogin(){

if (\Auth::attempt($this->credentials, $this->remember)) {
return \Redirect::route("dashboard");
}

}


It is not redirecting but coming back to
loginFormHandler
, which I know because it's not going to the dashboard page.

Answer

It's not possible. When you say return Redirect::route('dashboard'), its returning that function call to the calling function, rather than carrying out the function. By leaving off return, it still comes back to the calling function anyway.

I have since reorganised my logic.

Comments