Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

extjac's avatar

Query WhereYear() WhereInYear()

in my query I am able to do

whereYear() 

but i need something like

whereInYear()

how would you do it?

0 likes
3 replies
vumanhtrung's avatar

There is no whereInYear() query builder, you can use whereIn('year', $years) or create a dynamic scopeInYear()

public function scopeInYear($query, $years)
{
    return $query->whereIn('year', $years);
}
extjac's avatar

it is birthday....something like.... 2010-01-01

->whereYear('birthday', $year)
extjac's avatar
extjac
OP
Best Answer
Level 6

this seems to be working....

 $query->whereIn( \DB::raw('year(birthday)'), request()->year );

Please or to participate in this conversation.