Skip to content
Advertisement

empty data in Laravel query

my response always empty !

if I run only one (where) separated in the Query I get data

but

if I run all three ( where ) Its empty !

 $find= consultationsBridge::whereBetween(DB::raw('DATE(created_at)'), array($searchFrom, 
          $searchTo))
        ->where('branch',$branch)
        ->where('type',$type)
        ->paginate(50);

    return  $find;
    

my output

{
  "current_page": 1,
  "data": [
    
  ],
  "first_page_url": "http://127.0.0.1:8000/admin/search?page=1",
  "from": null,
  "last_page": 1,
  "last_page_url": "http://127.0.0.1:8000/admin/search?page=1",
  "next_page_url": null,
  "path": "http://127.0.0.1:8000/admin/search",
  "per_page": 50,
  "prev_page_url": null,
  "to": null,
  "total": 0
}

Advertisement

Answer

Change your controller code to something like this

$from = date($searchFrom);
$to = date($searchTo);
$find = consultationsBridge::whereBetween('created_at', [$from,$to])
            ->where([['branch',$branch],['type',$type]])
            ->paginate(50);
return  $find;

And if there’s an OR condition between branch and type then change your code like this

$from = date($searchFrom);
$to = date($searchTo);
$find = consultationsBridge::whereBetween('created_at', [$from,$to])
            ->where('branch',$branch)
            ->orWhere('type',$type)
            ->paginate(50);
return  $find;
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement