I am searching through a collection and I would like to have this search case insensitive or at least change the collections values in lowercase. How can I do that?
$value = strtolower($value);
$collection = $collection->where($attribute, $value);
$value is lowercase while the content in the collection not, so there are no matches.
You could instead use the filter()
method with a callback that does what you want:
$collection = $collection->filter(function ($item) use ($attribute, $value) {
return strtolower($item[$attribute]) == strtolower($value);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With