mercredi 21 août 2019

Laravel - where like returns all records

I am trying to do a search page and when my search form is empty i am getting all records from table instead of empty/null.

My route:

Route::get('/search', 'SearchController@index');

In controller I am doing it like this:

$query = $input["query"]; //getting query from form
$results = Table::where('name', 'LIKE', '%'.$query.'%')->get();

Output:

Collection {#1505 ▼

#items: array:5 [▶] (which is all records in table)

}

I am trying to get some empty collection or null.

Collection {#1505 ▼

#items: []

}



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2TQQcKk
via IFTTT

Aucun commentaire:

Enregistrer un commentaire