Use WhereMonth in the scope query Eg code :
public function scopeBirthdays($query)
{
return $query-> User::whereMonth('DOB' , Carbon::today()->month);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi! I'm making my first laravel project, using postgres, and I'd like to be able to access all the people with a birthday this month (my people table has a birthdate field that's a date). I can use extract to get these records from the database, like so:
select * from people where extract (month from birthdate) = 11;
But when I try a few different ways in my controller I get 'unknown column' errors:
$birthday_people = DB::table('people') ->where ("extract(month from birthdate)", "=", "11") ->get();
(I'll ultimately adjust it to compare with Carbon::now()->month, and use the model Person::all(), but until I get some results coming through I'm going as simple as possible)
Is there a special way to get extract to work in laravel? Or is there a different way to do this all together? Any help is greatly appreciated!
$data = DB::table('people')->whereRaw('extract(month from birthdate) = ?', ['11'])->get();
Please or to participate in this conversation.