How to order data by date and month not by year - Laravel

Viewed 39

Hlo there,am trying to show upcoming birthdays for 2 months (from today plus next month, no matter if today is 30th or 31st (date).

here is my code :

   " $data['user_birthdays'] = User::where('status', 1)
        ->where(function($query) {
            $query->whereMonth('dob', Carbon::now()->month)
                ->whereDay('dob', '>=', Carbon::now()->day)
                ->orWhereMonth('dob', Carbon::now()->addMonth(1)->month);
        })
        ->select(DB::raw("(DATE_FORMAT(dob, '%M-%D')) as dob"), 'users.*')->orderBy('dob', 'DESC')->get();   "

output-

see image

And i want to order birthdays by date and month.Its ordered by month only.How can i order this with date also.

0 Answers
Related