지금 당분간이 문제를 해결하려고 노력하고 있습니다.Laravel : 가격 피벗으로 제품 크기 관계를 추가하십시오.
그래서 Products 및 Size 테이블에는 많은 관계가 있습니다.
그래서 내 모델에서 내가 가진 :
public function sizes()
{
return $this->belongsToMany(Size::class, 'size_product')->withPivot('price');
}
내 양식은 다음과 같습니다
내 블레이드는 다음과 같습니다
<h2 class="fields-holder__title">Sizes</h2>
@foreach($sizes as $size)
<div class="field-holder__container">
<input type="checkbox" name="sizes[]" value="{{ $size->id }}">
<input type="text" name="prices[]" placeholder="Price">
</div>
@endforeach
을 그리고 내 컨트롤러 게시물에 내가 할 :
// add and remove sizes pivot
$sizes = [];
foreach ($request->sizes as $size) {
array_push($sizes, $size);
}
$product->sizes()->sync($sizes);
하지만 어떻게 가격을 절약 할 수 있습니까?
난 당신이 Laravel에서이 작업을 수행 할 수 있습니다 알고
$product->sizes()->sync($size, ['price' => $price]);
하지만 난 foreach 문이를 얻는 방법에 대해 설명합니다.
누군가가 나를 도울 수 있기를 바랍니다.
감사합니다.