Files
ladill-pos/app/Http/Controllers/Api/Mini/NotificationController.php
T
isaaccladandCursor e5d2b84388
Deploy Ladill Mini / deploy (push) Successful in 23s
Add Ladill POS v1 — register, Pay checkout, and commerce links.
Staff-facing counter register at pos.ladill.com with catalog cart, cash and
MoMo/card checkout via Ladill Pay, CRM timeline/import, invoice prefill, and
Merchant catalog import.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-23 22:52:24 +00:00

77 lines
2.2 KiB
PHP

<?php
namespace App\Http\Controllers\Api\Mini;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class NotificationController extends Controller
{
public function index(Request $request): JsonResponse
{
$account = ladill_account();
$notifications = $account->notifications()
->latest()
->limit(100)
->get()
->map(fn ($n) => $this->present($n));
$unread = $account->unreadNotifications()->count();
return response()->json([
'data' => $notifications,
'unread_count' => $unread,
]);
}
public function unreadCount(Request $request): JsonResponse
{
$account = ladill_account();
return response()->json([
'data' => [
'unread_count' => $account->unreadNotifications()->count(),
],
]);
}
public function markAsRead(Request $request, string $id): JsonResponse
{
$notification = ladill_account()
->notifications()
->where('id', $id)
->first();
if ($notification) {
$notification->markAsRead();
}
return response()->json(['data' => ['success' => true]]);
}
public function markAllAsRead(Request $request): JsonResponse
{
ladill_account()->unreadNotifications->markAsRead();
return response()->json(['data' => ['success' => true]]);
}
/** @return array<string, mixed> */
private function present(mixed $notification): array
{
return [
'id' => $notification->id,
'type' => class_basename($notification->type),
'title' => $notification->data['title'] ?? 'Notification',
'message' => $notification->data['message'] ?? '',
'icon' => $notification->data['icon'] ?? 'bell',
'milestone' => $notification->data['milestone'] ?? null,
'url' => $notification->data['url'] ?? null,
'read_at' => $notification->read_at?->toIso8601String(),
'created_at' => $notification->created_at?->toIso8601String(),
];
}
}