How do I know where the route came from and redirect back?

0

I have 3 tables in BD : Emitentes, Pessoas e Cidades . Being that in the Issuers table and in the People table I have FK id_cidade . When I am registering one, both Emitente and Pessoa have in the views a link that redirects me to the Cidades page:

Issuers / People:

{!! Form::label('id_cidade', 'Cidade:', ['class' => 'control-label']) !!}
{!! Form::text('id_cidade', $id_cidade, ['class' => 'form-control',  'readonly']) !!}
{!! Form::label('uf', 'UF:', ['class' => 'control-label']) !!}
{!! Form::text('uf', $nomeestado, ['class' => 'form-control', 'readonly']) !!}
<a href="{{ route('cidades.index') }}" class="btn btn-info" onClick="save()"> Selecionar&nbsp;&nbsp;<span class="glyphicon glyphicon-folder-open" aria-hidden="true"></span></a>

And on page cidades.index I have a link that redirects me to the Issuers page:

<tbody>@foreach($cidades as $cidade)<tr>
<td>
<a href="{{ URL::to('cidades/' . $cidade->id . '/selecionacidade') }}" class="btn btn-success">&nbsp;&nbsp;<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>&nbsp;&nbsp;</a>
</td>
<td>{{ e($cidade->cidade) }}</td>
<td>{{ e($cidade->estado) }}</td>

Route:

Route::get('cidades/{id}/selecionacidade','CidadesController@selecionacidade');

Controller Cities:

public function selecionacidade($id, Request $request){
  $request->session()->put('selecionacidade', 1);  
  $cidade = Cidade::findOrFail($id);  
  $request->session()->put('codigocidade', $id);  

  $request->session()->put('nomecidade', $cidade->cidade);
  $request->session()->put('nomeestado', $cidade->estado);
  $caminhocidade = $request->session()->get('caminhocidade'); //url de edição ou inserção
  $emitenteid = $request->session()->get('emitenteid');  
      return redirect()->route($caminhocidade, $emitenteid); } 

Everything works perfectly to register Issuers , but I tried to do the same for the People view, I made a new function in CidadesController to select the city to register People , I made a new route, and it continued to redirect me to view of Emission signup. So I was wondering if I would know how to view I was directed, and how could I be directed back to that view with id_cidade value stored. So working for the two registrations .

I apologize for the lengthy question, but did not see another way to specify what I needed.

    
asked by anonymous 03.04.2017 / 15:05

1 answer

2

If the purpose is to know where the route came from, you could capture globally or in a specific controller method what the current url is and send it to the session.

session(['url.previous' => $request->url()]);

return redirect('/novo_redirecionamento');

On the other page you would have the value of the previous url saved in session('url.previous') .

You can also use the headers for this:

$request->headers->get('referer')
    
07.04.2017 / 02:49