validate([ 'per_page' => 'nullable|integer|min:1|max:50', ]); $perPage = $validated['per_page'] ?? 10; $paginator = Notification::query() ->where('user_id', $request->user()->id) ->orderByDesc('id') ->paginate($perPage); $data = collect($paginator->items())->map(function ($notification) { return [ 'id' => $notification->id, 'type' => $notification->type, 'title' => $notification->title, 'body' => $notification->body, 'data' => $notification->data_json, 'is_read' => $notification->is_read, 'created_at' => $notification->created_at, ]; }); return response()->json([ 'data' => $data, 'meta' => [ 'current_page' => $paginator->currentPage(), 'per_page' => $paginator->perPage(), 'total' => $paginator->total(), 'last_page' => $paginator->lastPage(), ], ]); } }