wuschelino22
5 months ago
59
11
Laravel

Search function MYSQL

Posted 5 months ago by wuschelino22

Hello i want to bulid a search function. i use this code:

<form class="form-inline my-2 my-lg-0" action="/search" method="post">
        {{ csrf_field() }}
      <input class="form-control mr-sm-2" name="search" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>

and my /search function is this

public function search(Request $request)
    {
    $urls = Url::where('name', $request->get('search'))
    ->orWhere('name', 'like', '%' . $request->get('search') . '%')->get();

    $shares = $urls;

    return view('index', compact('shares'));

and this is my web.php



Route::post('search', '[email protected]');

i get the follow error message but i dont know where the variable is missing

rrorException (E_ERROR) Undefined variable: categories (View: C:\xampp\htdocs\Linkliste\resources\views\index.blade.php)

Thank you

Please sign in or create an account to participate in this conversation.