how to make redirects in laravel

-1

Well, first of all thanks to the users of this community for helping me repeatedly with my doubts in PHP, THANKS! Today my question is something totally new for me, I am new to laravel and I have a project created in pure PHP working, I want to make my app more secure and easier, that is why I decided to learn a bit about Laravel, the detail is that I know how to redirect a user (once you log in) to a form as long as he has not purchased a membership, if he already bought it, redirect him to the start page, please if he could help me, I repeat that I am very new in Laravel. practically Basic.

    
asked by Abdiel Hernandez 13.06.2018 в 05:49
source

2 answers

1

In the controller you include the facade "use Illuminate \ Support \ Facades \ Auth;" and then to verify that the user is logged in and has membership

if(Auth::check()){
   $usuario = Auth::user();
   if($usuario->membresia == 0){
     return redirect()->to($url); // SI VAS A UNA URL ESPECIFICA.
     return view('formulario') // O SI QUIERES IR A LA VISTA.
   }else{
     return view('inicio');
   }
}
    
answered by 13.06.2018 / 10:51
source
0

Path Customization When a user is successfully authenticated, they will be redirected to the / home URI. You can customize the post-authentication redirect location by defining to redirectTo property on the LoginController, RegisterController, and ResetPasswordController:

protected $redirectTo = '/';

Next, you should modify the RedirectIfAuthenticated middleware's handle method to use your new URI when redirecting the user.

If the redirect path needs custom generation logic you define redirectTo method instead of a redirectTo property:

protected function redirectTo()
{
    return '/path';
}

Remember that if you learn a framework this facilitates your documentation, in this case Laravel has a very telling and easy to understand.

  

link

    
answered by 13.06.2018 в 22:34