Answer the question
In order to leave comments, you need to log in
How to make a selection from the product database?
There is a code by which I sort the goods with the hasMany connection .
$vendor = $request->vendor;
$products = Product::with('user')
->when($vendor, function ($query, $vendor) {
$query->where('vendor_id', $vendor);
})
->paginate(15);
->when($size, function ($query, $size) {
$query->where('size_id', $size); //----эта строка не правильна потому что
// у меня id в промежуточной таблице
})
$products = [
'item_1' => [
'id' => 1,
'name' => 'product_1',
'size' => 'S'
],
'item_2' => [
'id' => 2,
'name' => 'product_2',
'size' => 'XL',
],
'item_3' => [
'id' => 3,
'name' => 'product_3',
'size' => 'S',
],
'item_4' => [
'id' => 3,
'name' => 'product_5',
'size' => 'L',
],
];
$sizes = [
'size' => [
'id' => 1,
'name' => 'S',
],
'size_2' => [
'id' => 2,
'name' => 'L',
],
'size_3' => [
'id' => 3,
'name' => 'XL',
],
];
$prosuct_size = [
'id' => [
'product_id' => 1,
'size_id' => 1,
],
'id' => [
'product_id' => 3,
'size_id' => 1,
],
'id' => [
'product_id' => 4,
'size_id' => 2,
],
]
<div class="size">
<input type="checkbox" name="size" value="size[i][id]">
<button>click</button>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question