Channel
This commit is contained in:
@@ -20,7 +20,7 @@ class CollectionController extends Controller
|
||||
{
|
||||
return response()->rest(
|
||||
CollectionResource::collection(
|
||||
Collection::with('media')->where('is_visible', true)->ordered()->get()
|
||||
Collection::query()->with('media')->where('is_visible', true)->inRandomOrder()->get()
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -34,7 +34,7 @@ class CollectionController extends Controller
|
||||
|
||||
return response()->rest_paginate(
|
||||
CollectionResource::collection(
|
||||
Collection::with('media')->where('is_visible', true)->ordered()->simplePaginate($perPage)
|
||||
Collection::query()->with('media')->where('is_visible', true)->inRandomOrder()->simplePaginate($perPage)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api\V1\Filters;
|
||||
|
||||
use App\Http\Controllers\Api\V1\Filters\Requests\FilterIndexRequest;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Ecommerce\Channel\Channel;
|
||||
use App\Models\Ecommerce\Product\Brand\Brand;
|
||||
use App\Models\Ecommerce\Product\Category\Category;
|
||||
use App\Models\Ecommerce\Product\Collection\Collection;
|
||||
@@ -51,6 +52,10 @@ class FilterController extends Controller
|
||||
return $this->filterByCategoryResource(Brand::find($this->request->brand_id));
|
||||
}
|
||||
|
||||
if ($this->shouldFilterByChannel()) {
|
||||
return $this->filterByCategoryResource(Channel::find($this->request->channel_id));
|
||||
}
|
||||
|
||||
return Category::query()->where('is_visible', true)->ordered()->get(['id', 'parent_id', 'name']);
|
||||
}
|
||||
|
||||
@@ -127,4 +132,12 @@ class FilterController extends Controller
|
||||
{
|
||||
return $this->request->filled('brand_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if request should be filtered by channel
|
||||
*/
|
||||
private function shouldFilterByChannel(): bool
|
||||
{
|
||||
return $this->request->filled('channel_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ class FilterIndexRequest extends FormRequest
|
||||
'collection_id' => ['bail', 'nullable', 'int', 'exists:collections,id'],
|
||||
'category_id' => ['bail', 'nullable', 'int', 'exists:categories,id'],
|
||||
'brand_id' => ['bail', 'nullable', 'int', 'exists:brands,id'],
|
||||
'channel_id' => ['bail', 'nullable', 'int', 'exists:channels,id'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user