This commit is contained in:
Mekan1206
2026-05-02 16:16:56 +05:00
parent 40cac31648
commit 62f8deb51f
2 changed files with 18 additions and 13 deletions

View File

@@ -62,29 +62,29 @@ class FilterController extends Controller
private function brands()
{
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()) {
$brands = Category::find($this->request->category_id)->products()
$brands = Category::query()->find($this->request->category_id)->products()
->where('products.is_visible', true)
->where('products.parent_id', null)
->where('products.stock', '>', 0)
->distinct('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()) {
$brands = Collection::find($this->request->collection_id)->products()
$brands = Collection::query()->find($this->request->collection_id)->products()
->where('products.is_visible', true)
->where('products.parent_id', null)
->where('products.stock', '>', 0)
->distinct('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']);
@@ -102,13 +102,18 @@ class FilterController extends Controller
->distinct('products.id')
->pluck('products.id');
return Category::where('is_visible', true)
->ordered()
->join('product_has_relations', 'categories.id', '=', 'product_has_relations.productable_id')
->where('product_has_relations.productable_type', '=', 'category')
->whereIntegerInRaw('product_has_relations.product_id', $products)
->get(['categories.id', 'categories.parent_id', 'categories.name'])
->unique('categories.id');
return Category::query()
->distinct('categories.id')
->where('is_visible', true)
->join('product_has_relations', 'categories.id', '=', 'product_has_relations.productable_id')
->where('product_has_relations.productable_type', '=', 'category')
->whereIntegerInRaw('product_has_relations.product_id', $products)
->get()
->map(fn ($category) => [
'id' => $category->id,
'parent_id' => $category->parent_id,
'name' => $category->name,
]);
}
/**

View File

@@ -17,11 +17,11 @@ use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Spatie\DeletedModels\Models\Concerns\KeepsDeletedModels;
use Spatie\Permission\Traits\HasRoles;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{