I did a search and I want to display the result, but I cannot convey the variable to the view, although I specify it in the controller.
My piece of view code:
<div class='search col-md-6'>
<p>Найти сотрудника по id</p>
<form action="" method="GET" class="search-id">
<div class="row">
<div class="col-xs-10">
<div class="form-group">
<input type="text" class="form-control" name="id" value="" required>
</div>
</div>
<div class="col-xs-2">
<div class="form-group">
<input class="btn btn-info" type="submit" value="Искать">
</div>
</div>
</div>
</form>
<div>
my route:
Route::match(['get', 'post'], 'searchID', 'SearchController@indexID')->name('searchID');
my method in the controller:
public function indexID(Request $request, View $view)
{
//$message= "Сотрудник не найден";
$id= $request->input('id');
dump($id);
$result = Staff::where('public_id', $id)->get();
if($result == null)
{
//dump($message);
return redirect()->back()->withInput($id);
}
else
{
dump($result);
return view('addworker')->with('result', $result);
}
}
But I constantly get an error: Undefined variable: result
I tried:
return view('addworker')->with($result);
and
return view('addworker',$result);
and
return view('addworker', ['result', $result]);
None of this helped me, I don't know what to do anymore
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire