mardi 20 novembre 2018

laravel redirection to previous page after login

I have a view (URL: /equip-planner) with a form like this:

<form action="" method="POST" class="form-horizontal">
  
  <input type="text" id="name" name="name" class="form-control-sm">
  <button type="submit" class="btn btn-primary btn-sm">
    <i class="fa fa-btn fa-plus">Create</i>
  </button>    
</form>

Routes:

Route::get('/equip-planner', 'EquipmentController@ep')->name('equip-planner');
Route::resource('equips', 'EquipmentController');

Controller Constructor:

public function __construct(){
        $this->middleware('auth', ['except' => ['index', 'show','create','home','ep']]);
    }

When I submit my form it will at first check if the user is logged in since the resource method "store" is not listed in the except list within the controller's constructor. So, if the user is not logged in, he will be redirected to the login page which is just fine. BUT: After successful login the user will be redirected to /equips instead of /equip-planner. I guess this is because of the form action ([...]action="[...]).

Does anyone have an idea how to change the redirection so the user will be sent back to /equip-planner? ...is it even possible? I think there must be another step back since the steps are: /equip-planner -> /equips -> login -> back to site before, which is /equips ?

Thanks in advance!

Andreas



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire