- public function getPaginatedByType($type, $page = 0, $pageSize = 24, $userFilter = false)
- {
- $images = $this->image->where('type', '=', strtolower($type));
+ public function getPaginatedByType(
+ string $type,
+ int $page = 0,
+ int $pageSize = 24,
+ ?int $uploadedTo = null,
+ ?string $search = null,
+ ?callable $whereClause = null
+ ): array {
+ $imageQuery = Image::query()->where('type', '=', strtolower($type));
+
+ if ($uploadedTo !== null) {
+ $imageQuery = $imageQuery->where('uploaded_to', '=', $uploadedTo);
+ }
+
+ if ($search !== null) {
+ $imageQuery = $imageQuery->where('name', 'LIKE', '%' . $search . '%');
+ }
+
+ // Filter by page access
+ $imageQuery = $this->permissions->restrictPageRelationQuery($imageQuery, 'images', 'uploaded_to');