iHmD
2 years ago
9385
8
Laravel

Get Current Month data in the User model!

Posted 2 years ago by iHmD

I want to get the current month's data, in my controller I can do that like so:

        $myMonthApts = DB::table('appointments')
                        ->where('agent_id', $request->user()->id)
                        ->whereIn('status_id', [3,4])
                        ->whereYear('created_at', Carbon::now()->year)
                        ->whereMonth('created_at', Carbon::now()->month)
                        ->count();

but I Can't do the same thing in the User model using custom functions because I get the error (Method whereYear and whereRaw don't exist)

Please sign in or create an account to participate in this conversation.