Reputation: 373
I want to find by letter customer's first_name on my 'customers' table.
And the only thing that I get is an empty array.
For instance, I put in the parameter 'q' value 'E' to get customer Elena from my database by I get an only empty array.
I use the following code to get first_name : $search = Input::get('q');
if($search)
{
$customers = Customer::all()->where('full_name', 'LIKE', "%{$search}%");
return ($customers);
}
Can someone help me?
Upvotes: 0
Views: 999
Reputation: 2166
Try this
$customers = Customer::where('full_name', 'LIKE', "%{$search}%")->get();
Upvotes: 0
Reputation: 10264
Your query don't work because you are calling the all()
method before the where()
. That's actually not wrong, but it have different behavior.
When you call all()
, it actually does the SQL query. After that, any chained methods are being called into a Eloquent Collection
class, and it also have a where method, but that's simpler since it runs on PHO instead of running on SQL.
Since the collection's where()
method doesn't support LIKE operator, it's probably searching for a value that is exactly %E%
.
Hope it can help you understanding why your query doesn't work as expected.
Upvotes: 3