where('user_id', $user->id) ->latest() ->first(); } public function getInvoiceOfMonth(User $user, int $latestInvoiceNumber): Invoice { return Invoice::query() ->thisMonth() ->firstOrCreate( [ 'user_id' => $user->id, ], [ 'invoice_number' => $latestInvoiceNumber, 'issue_date' => now()->toDateString(), 'created_by' => Auth::check() ? auth()->id() : null, ] ); } public function getInvoiceByPublishedDate($year,$month): Invoice { return Invoice::whereYear('created_at', '=', $year) ->whereMonth('created_at', '=', $month) ->first(); } }