D
D
Danila5342020-11-19 20:56:08
Laravel
Danila534, 2020-11-19 20:56:08

Extracting information from a search?

Good evening,
Somehow I did 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 cares, please help :3

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daria Motorina, 2020-11-19
@Danila534

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 only need to create this template, add sections and base layout to it, and display $name and $item in the template.
The only thing is that creating urls of such a plan (search1) is bad, it is better to replace it with something more human-readable and without numbers (you can even split one search url into GET /search and POST /search with reference to different actions).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question