WIP
This commit is contained in:
@@ -62,29 +62,29 @@ class FilterController extends Controller
|
|||||||
private function brands()
|
private function brands()
|
||||||
{
|
{
|
||||||
if ($this->shouldFilterByBrand()) {
|
if ($this->shouldFilterByBrand()) {
|
||||||
return Brand::where('id', $this->request->brand_id)->get(['id', 'name']);
|
return Brand::query()->where('id', $this->request->brand_id)->get(['id', 'name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->shouldFilterByCategory()) {
|
if ($this->shouldFilterByCategory()) {
|
||||||
$brands = Category::find($this->request->category_id)->products()
|
$brands = Category::query()->find($this->request->category_id)->products()
|
||||||
->where('products.is_visible', true)
|
->where('products.is_visible', true)
|
||||||
->where('products.parent_id', null)
|
->where('products.parent_id', null)
|
||||||
->where('products.stock', '>', 0)
|
->where('products.stock', '>', 0)
|
||||||
->distinct('products.brand_id')
|
->distinct('products.brand_id')
|
||||||
->pluck('products.brand_id');
|
->pluck('products.brand_id');
|
||||||
|
|
||||||
return Brand::whereIntegerInRaw('id', $brands)->get(['id', 'name']);
|
return Brand::query()->whereIntegerInRaw('id', $brands)->get(['id', 'name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->shouldFilterByCollection()) {
|
if ($this->shouldFilterByCollection()) {
|
||||||
$brands = Collection::find($this->request->collection_id)->products()
|
$brands = Collection::query()->find($this->request->collection_id)->products()
|
||||||
->where('products.is_visible', true)
|
->where('products.is_visible', true)
|
||||||
->where('products.parent_id', null)
|
->where('products.parent_id', null)
|
||||||
->where('products.stock', '>', 0)
|
->where('products.stock', '>', 0)
|
||||||
->distinct('products.brand_id')
|
->distinct('products.brand_id')
|
||||||
->pluck('products.brand_id');
|
->pluck('products.brand_id');
|
||||||
|
|
||||||
return Brand::whereIntegerInRaw('id', $brands)->get(['id', 'name']);
|
return Brand::query()->whereIntegerInRaw('id', $brands)->get(['id', 'name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Brand::query()->where('is_visible', true)->ordered()->get(['id', 'name']);
|
return Brand::query()->where('is_visible', true)->ordered()->get(['id', 'name']);
|
||||||
@@ -102,13 +102,18 @@ class FilterController extends Controller
|
|||||||
->distinct('products.id')
|
->distinct('products.id')
|
||||||
->pluck('products.id');
|
->pluck('products.id');
|
||||||
|
|
||||||
return Category::where('is_visible', true)
|
return Category::query()
|
||||||
->ordered()
|
->distinct('categories.id')
|
||||||
->join('product_has_relations', 'categories.id', '=', 'product_has_relations.productable_id')
|
->where('is_visible', true)
|
||||||
->where('product_has_relations.productable_type', '=', 'category')
|
->join('product_has_relations', 'categories.id', '=', 'product_has_relations.productable_id')
|
||||||
->whereIntegerInRaw('product_has_relations.product_id', $products)
|
->where('product_has_relations.productable_type', '=', 'category')
|
||||||
->get(['categories.id', 'categories.parent_id', 'categories.name'])
|
->whereIntegerInRaw('product_has_relations.product_id', $products)
|
||||||
->unique('categories.id');
|
->get()
|
||||||
|
->map(fn ($category) => [
|
||||||
|
'id' => $category->id,
|
||||||
|
'parent_id' => $category->parent_id,
|
||||||
|
'name' => $category->name,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ use Illuminate\Database\Eloquent\Casts\Attribute;
|
|||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||||
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
use Laravel\Sanctum\HasApiTokens;
|
use Laravel\Sanctum\HasApiTokens;
|
||||||
use Spatie\DeletedModels\Models\Concerns\KeepsDeletedModels;
|
use Spatie\DeletedModels\Models\Concerns\KeepsDeletedModels;
|
||||||
use Spatie\Permission\Traits\HasRoles;
|
use Spatie\Permission\Traits\HasRoles;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
||||||
|
|
||||||
class User extends Authenticatable
|
class User extends Authenticatable
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user