|
5 | 5 | use Pterodactyl\Models\Node; |
6 | 6 | use Illuminate\Http\JsonResponse; |
7 | 7 | use Pterodactyl\Models\Allocation; |
| 8 | +use Spatie\QueryBuilder\QueryBuilder; |
| 9 | +use Spatie\QueryBuilder\AllowedFilter; |
| 10 | +use Illuminate\Database\Eloquent\Builder; |
8 | 11 | use Pterodactyl\Services\Allocations\AssignmentService; |
9 | 12 | use Pterodactyl\Services\Allocations\AllocationDeletionService; |
10 | 13 | use Pterodactyl\Transformers\Api\Application\AllocationTransformer; |
@@ -43,7 +46,20 @@ public function __construct( |
43 | 46 | */ |
44 | 47 | public function index(GetAllocationsRequest $request, Node $node): array |
45 | 48 | { |
46 | | - $allocations = $node->allocations()->paginate($request->query('per_page') ?? 50); |
| 49 | + $allocations = QueryBuilder::for($node->allocations()) |
| 50 | + ->allowedFilters([ |
| 51 | + AllowedFilter::exact('ip'), |
| 52 | + AllowedFilter::exact('port'), |
| 53 | + 'ip_alias', |
| 54 | + AllowedFilter::callback('server_id', function (Builder $builder, $value) { |
| 55 | + if (empty($value) || is_bool($value) || !ctype_digit((string) $value)) { |
| 56 | + return $builder->whereNull('server_id'); |
| 57 | + } |
| 58 | + |
| 59 | + return $builder->where('server_id', $value); |
| 60 | + }), |
| 61 | + ]) |
| 62 | + ->paginate($request->query('per_page') ?? 50); |
47 | 63 |
|
48 | 64 | return $this->fractal->collection($allocations) |
49 | 65 | ->transformWith($this->getTransformer(AllocationTransformer::class)) |
|
0 commit comments