Add notification inbox, toasts and alert scanner for orders, prints and filament
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 28s
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 28s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
04be9802dc
commit
ab1fdb961f
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Notifications\DatabaseNotification;
|
||||
|
||||
class NotificationController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
return response()->json([
|
||||
'unread' => $user->unreadNotifications()->count(),
|
||||
'items' => $user->notifications()->latest()->limit(20)->get()->map(fn (DatabaseNotification $notification): array => [
|
||||
'id' => $notification->id,
|
||||
'kind' => $notification->data['kind'] ?? 'info',
|
||||
'title' => $notification->data['title'] ?? '',
|
||||
'body' => $notification->data['body'] ?? '',
|
||||
'level' => $notification->data['level'] ?? 'info',
|
||||
'url' => $notification->data['url'] ?? null,
|
||||
'read' => $notification->read_at !== null,
|
||||
'time' => $notification->created_at->diffForHumans(),
|
||||
])->all(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function read(Request $request, string $notification): JsonResponse
|
||||
{
|
||||
$request->user()->notifications()->whereKey($notification)->first()?->markAsRead();
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
public function readAll(Request $request): JsonResponse
|
||||
{
|
||||
$request->user()->unreadNotifications->markAsRead();
|
||||
|
||||
return response()->json(['ok' => true]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user