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);