Call to Undefined method Illuminate Database Query Joinclause::whereBetween() Laravel 5.2

Asked

Viewed 497 times

0

I have this error in my consultation, I have identified that the use of whereBetween within a function join is impossible to use, but I saw that the staff was able to use the DB::Raw and replace that whereBetween.

The point is I haven’t found any examples of using DB::Raw within a function join and the ways I tried were not successful.

Code:

$exec = DB::table('execucao_acompanhamento as a')
        ->join('execucao_acompanhamento_busca_bens as h', function($join)
                                          use($data_busca_1_1, $data_busca_1_2){
            $join->on('a.id','=','h.acompanhamento_id')
                ->where('h.busca_bens_id','=','1')
                ->whereBetween('h.data_busca', ["$data_busca_1_1","$data_busca_1_2"]);
        })
        ->get();
  • See this: https://stackoverflow.com/a/37298384/1518921

  • So, as I want to compare between a period, wherein does not help me in this case, because wherein checks inside an array if in that table there is the value 1 and 10 for example, but in my case I have to check if there are values within the range 1 and 10.

  • Luiz I understand, but the idea is not to use it exactly like this, but rather understand how he used raw and adapted, so you adjust and adapt to your case, understand? I can’t tell if it’ll work for you, but if I can test your code I’ll try to see if there’s a way to create an alternative.

  • Right, but in this example he used raw only for a Raw, as far as I know, it is not possible to use a between inside a raw. Or is it possible? I tried some form here and did not succeed.

1 answer

1

I have been looking at other forums and found how to replace the whereBetween. It looked like this.

$exec = DB::table('execucao_acompanhamento as a')
->join('execucao_acompanhamento_busca_bens as h', function($join) use($data_busca_1_1, $data_busca_1_2){
    $join->on('a.id','=','h.acompanhamento_id')
        ->where('h.busca_bens_id','=','1')
        ->where('j.data_busca','>=', $data_busca_1_1)
        ->where('j.data_busca','<=', $data_busca_1_2);
})
->get();
  • I tested with 5.4 and whereBetween worked normal in this same context. But since I don’t know the behavior of 5.2, then I believe your answer is the right one.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.