0
I’ve been trying for a while to make a route work, but so far nothing...
Controller:
public function profissionais(Request $request, $id){
$vinculo = session()->get('vinculo');
$profissionais = Vinculo::where('unidade_id', '=', $id)->get();
$unidades = Unidade::where('municipio_id', '=', $vinculo->usuario->municipio_id)
->get();
$profissionais = $id;
return view('relatorios.profissionais', compact('unidades', 'profissionais'));
}
Form:
<form method="GET" action="{{route('relatorios.profissionais', 'id')}}">
<select class="js-example-basic-single" name="id" required>
@foreach($unidades as $unidade)
<option value="{{$unidade->id}}">{{$unidade->descricao}}</option>
@endforeach
</select>
<span class="input-group-btn">
<button class="btn btn-primary" type="submit">Listar</button>
</span>
</form>
web php.:
Route::get('/relatorios/profissionais/{id}', 'RelatorioController@profissionais')->name('relatorios.profissionais');
I’ve tried it anyway, but I see I still don’t understand the logic in the system...
What I want is for the url to appear like this: /relatorios/profissionais/4
and the controller receives the number 4 in the variable $id
and seek the links.
But at the moment the url is being shown like this: relatorios/profissionais/id?id=4
The second parameter of the route method that is in the attr action of the form must be an id (numeral). 4 or '4' {route('reports.professionals', 4)}} But you still can’t understand... I think I needed to see your javascript for this. Maybe put the route inside the foreach, in the attr value of each option... Then in the select change event you exchange the form attributo action. <option value="{{route('reports.professionals', $unit->id)}}">
– cau