John Davidson

php - to lower case in laravel eloquent query


i´m traying to get of my DB to lowercase column data with model::where

this is my query:

$restaurants = Restaurant::where('name', 'LIKE', "%".$search."%")->get();

$results = [];

foreach ($restaurants as $r) {
$data = array(
'id' => $r->id,
'label' => $r->name,
'value' => $r->name,
'url' => $r->url,
array_push($results, $data);

i´m traying with this:

$restaurants = Restaurant::whereRaw('LOWER(name) = ?', [$search])->get();

but return empty results.

How i would can to do this?. In my database it´s all in uppercase i need search in uppercase or lowercase

Thanks for help

My Answer:

foreach($restaurants as $restaurant){
$restaurant->name = strtolower($restaurant->name);

Rate this post

5 of 5 based on 4210 votes


© 2024 - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us