php - laravel nested relationships pivot table

this is my database tables that each product can have multiple attributes and each attribute has multiple values that can be selected in the Select Box on the product edit page.
attribute table:
+
attribute_values table:
{-code-2}
products table:
{-code-3}
attribute_product table:
{-code-4}
relationships
{-code-5}
blade:
{-code-6}
how to add 'selected' to select box selected options (value_id in attribute_product)?
Answer
Answer
Answer
Answer
Answer
Solution:
You just need to do
@foreach($product->attributes as $attribute)
Attribute Name: {{ $attribute->name }}
<select>
@foreach($attribute->values as $value)
<option id="{{ $value->id }}" {{ $attribute->pivot->value_id == $value->id ? 'selected' : '' }} >{{ $value->id }}</option>
@endforeach
</select>
@endforeach
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: the browser (or proxy) sent a request that this server could not understand.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.