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[]">
@foreach($mysliwski as $mysl)
@if(!$product->categories->isEmpty())
@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
@else
<option value="{{$mysl->id}}">{{$mysl->name}}</option>
@endif
@endforeach
</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. Where I have bug?