32 lines
889 B
PHP
32 lines
889 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\ClientInvoice;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class NotificationController extends Controller
|
|
{
|
|
public function index(): JsonResponse
|
|
{
|
|
$pendingInvoiceCount = ClientInvoice::query()
|
|
->whereNull('approved_at')
|
|
->count();
|
|
|
|
$notifications = collect([
|
|
[
|
|
'type' => 'pending_invoice',
|
|
'title' => 'Pending invoice approvals',
|
|
'description' => 'Client invoices waiting for approval',
|
|
'count' => $pendingInvoiceCount,
|
|
],
|
|
])->filter(fn (array $notification) => $notification['count'] > 0)->values();
|
|
|
|
return response()->json([
|
|
'count' => $notifications->sum('count'),
|
|
'notifications' => $notifications,
|
|
]);
|
|
}
|
|
}
|