Added Notifications

This commit is contained in:
2026-05-10 22:42:37 +10:00
parent 016e752dcd
commit c7fe3268c7
18 changed files with 1386 additions and 50 deletions
@@ -4,11 +4,34 @@ namespace App\Http\Controllers;
use App\Models\Notification;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class NotificationController extends Controller
{
use AuthorizesRequests;
public function index(Request $request): JsonResponse
{
$user = $request->user();
$unread = $user->notifications()
->whereNull('read_at')
->latest()
->get();
if ($unread->isNotEmpty()) {
return response()->json($unread);
}
$recent = $user->notifications()
->latest()
->limit(10)
->get();
return response()->json($recent);
}
public function markRead(Request $request, Notification $notification)
{
$this->authorize('update', $notification);
@@ -29,6 +29,7 @@ class HandleInertiaRequests extends Middleware
*/
public function share(Request $request): array
{
return [
...parent::share($request),
'logo_api_url' => config('app.logo_api_url'),
@@ -44,6 +45,11 @@ class HandleInertiaRequests extends Middleware
->latest()
->get()
: [],
'unread_notification_count' => $request->user()?->notifications()
->whereNull('read_at')
->whereNull('expires_at')
->orWhere('expires_at', '>', now())
->count(),
];
}
}