How can I implement a search engine in laravel 5.8?

  crud, laravel, php, search

I am trying to put a search engine in my laravel page, but I have a lot of difficulties to be able to achieve it, clearly I cannot find the way to work correctly. the version of laravel I use is 5.8. I leave the code to see if someone can help me!

Form in index.blade.php

<li class="nav-item">
            <form class="form-inline search-box">
            <input class="form-control rounded-pill search-input" name="search" type="search" placeholder="Buscar..." aria-label="Search" />

My RegistryController.php

    $registries = Registry::all()->toArray();
    return view('registries.index', compact('registries'));

 * Show the form for creating a new resource.
 * @return IlluminateHttpResponse

public function search(Request $request)
    $search = $request->get('search');
    $registries = DB::table('registries')->where('nombre', 'like', '%'. $search .'%')->paginate(5);
    return view('index', ['registries' => $registries]);

And my route

Route::get('search', '[email protected]')-> name('search');

Source: Laravel

Leave a Reply