0
Good morning everyone, I’m having a little problem here on a search of the Laravel, I’ve thought of several things but I couldn’t solve. I have a table rendered in a view and some buttons in this table that take me to the desired functions for each item, as expected, and a search field, so far everything works normal, goes to the functions when clicked and search as it should however, after the search, I can not access any of the functions for the searched item, after the search, the ID is lost and no longer enters the url, "just pass the id" I know it is obvious but I do not know how to do since the return of the search is the same previous page, then if you pass the ID on the route it will be bad to access this same view by another way(main).
Follow a screen print after the search:
Here is the search function in the controller:
//Pesquisar Máquina
public function machineSearch(Request $request)
{
$setor = Setores::all();
$resultado = [];
$nomes= '';
$maquina = ManutencaoMaquinas::where('descricao', $request->conteudo)
->orwhere('patrimonio', $request->conteudo)
->select('descricao', 'patrimonio')
->orderBy('id')
->paginate(14);
$maquinaPesquisa = ManutencaoMaquinas::select('descricao')
->orderBy('id')
->get();
$user = Auth::user();
$userid = $user->id;
foreach ($maquinaPesquisa as $maquinas) {
$resultado[] = '"'.trim($maquinas).'"';
}
if ($resultado <> []) {
$nomes = (implode(',', $resultado));
}
return view('portal.manutencao.maquinas.index',
compact( 'user', 'userid', 'setor', 'maquina', 'nomes'));
}
I know I could try a find(id) but I could not go by route, there is some other way to pass this ID?
Here as the search is called in the view:
<div class="ml-auto float-right">
{!! Form::open(['route'=>'manutencao-maquina-pesquisa', 'method'=>'post', 'class' => 'form-inline ml-auto float-right ', 'onsubmit'=>'ShowLoading()']) !!}
<strong style="margin-right: 10px"><h4>Pesquisar Máquina:</h4></strong>
@include('portal.manutencao.maquinas._maqSearch-form')
{!! Form::close() !!}
</div>
_maqSearch-form:
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1"><i class="fa fa-search"></i></span>
</div>
<input type="text" class="form-control" id="conteudo" name="conteudo" placeholder="Máquina..." aria-describedby="basic-addon1">
{{--<input type="text" class="form-control" id="patrimonio" name="patrimonio" placeholder="Patrimônio..." aria-describedby="basic-addon1">--}}
<div class="input-group-append">
<button class="btn btn-primary" type="submit">Pesquisar</button>
</div>
Finally the route:
Route::get('', ['as' => 'manutencao-servicos', 'uses' => 'ManutencaoController@servicoIndex']);
I hope you’ve managed to explain my doubt and if anyone can help I’m very grateful.
If you need more information I’m here.
Grateful once again.
How is the view code of include 'portal.maintenance.maquinas. _maqSearch-form'?
– José Veiga
Thanks @Joséveiga, I edited the issue with the code you asked for...
– Gabriel Sassaki