Displaying information from a search?
-
Good evening,
Something like doing a search on the site, which, in theory, should search for information from the database ...
But I don’t understand how to display information on the site ..
public function search(Request $request) { $name = $request->input('Name'); $item = DB::connection('555')->table('Shop_Goods')->where('name', 'LIKE', '%' . $name . '%')->get(); return view('adminka.test')->with($name, $item); }
Route::get('search', 'Admin\[email protected]')->name('search'); Route::post('search1', 'Admin\[email protected]')->name('search1');
<form action="/search1" accept-charset="UTF-8" method="post"> {!! csrf_field() !!} <input type="text" id="Name" name="Name" placeholder="Название предмета"> <input type="submit" value="Найти"> </form>
Who is not difficult, please help: 3Laravel Blake Haley, Jun 25, 2020 -
Look, now you have already written the output of the results to the admin / test.blade.php template in the controller
public function search(Request $request)
{
$name = $request->input('Name');
$item = DB::connection('555')->table('Shop_Goods')->where('name', 'LIKE', '%' . $name . '%')->get();
return view('adminka.test')->with($name, $item);
}
Here you just need to create this template, add the sections and base layout to it and display $ name and $ item in the template.
The only thing that creating urls of such a plan (search1) is bad, it is better to replace it with something more understandable and without numbers (you can even split one search url into GET / search and POST / search with binding to different actions).Eliot Solis
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!