0

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
}
3
  • Can you please remove the paginate function for now, and try the function toSql instead of that for once? You'll get the entire query that is being generated by Laravel. Moreover, to find the exact value that is being used by Laravel you can use the function "getBindings". Combining these 2 results please verify the output again. Commented Jul 6, 2020 at 8:03
  • I think your whereBetween is wrong, why are you using DB::raw('DATE(created_at)') as first param, maybe you need use simply 'created_at' ? Commented Jul 6, 2020 at 8:23
  • thanks guys the next answer is right ! Commented Jul 6, 2020 at 12:05

1 Answer 1

1

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;
Sign up to request clarification or add additional context in comments.

1 Comment

@AndrewNady My pleasure !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.