Home > Software engineering >  How to use whereBetween in whereRelation Laravel 8
How to use whereBetween in whereRelation Laravel 8

Time:04-08

I want to use something like whereBetween or another to filter created_at in 'accountLog' model using whereRelation

Account::with('accountLog')->get();

how can i do that?

CodePudding user response:

I think its not available yet if you want to use whereBetween capabilities using whereRelation

Hence, you can achieve same way like this

Account::with('accountLog', function($query) use ($start, $end) {
    $query->whereBetween('created_at', [$start, $end])
})->get();

CodePudding user response:

whereBetween is just like where and you can use it the same way :

Account::with('accountLog')->whereBetween('created_at', [$startDate, $endDate])

You should check the doc : https://laravel.com/docs/9.x/queries#additional-where-clauses

  • Related