I have two arrays of objects and I want to check if ids of elements of both are the same then select option in select box otherwise just display it. I tried like this:
<select multiple class="form-control" name="category_id[]">
@if(!$product->categories->isEmpty())
@foreach($mysliwski as $mysl)
@foreach($product->categories as $cat)
@if($mysl->id == $cat->id)
<option selected value="{{$mysl->id}}">{{$mysl->name}}</option>
@else
<option value="{{$mysl->id}}">{{$mysl->name}}</option>
@endif
@endforeach
@endforeach
@else
@foreach($mysliwski as $mysl)
<option value="{{$mysl->id}}">{{$mysl->name}}</option>
@endforeach
@endif
</select>
But it works only when one category is the same. When there are more my select option are duplicated. Here are my two arrays http://laravel.io/bin/ro5rM Where I have bug?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community