php - Laravel: How to Compare 2 Collection Attributes
I am sending data to my view as below;
I am displaying all contacts in a multi select form and trying to get "selected" printed in options listings. (Then I will use jquery to populate the select field with chosen plugin) In my other pages, nested foreach loop works(something like below), it works@if
check is checking against a single value. But now, I have multiple values to check. Nested foreach loop fails (see below)
$contacts = ContactDirectory::where('customer_id', Auth::user()->customer_id)->get(); //Say 50 contacts
$rfito = rfito::where('rfi_id',$rfiid)->get(); // say 5 contacts
then
@foreach ($contacts as $contact)
@foreach ($rfito as $rfito)
<option value="{{$contact->id}}" @if($contact->id == $rfito->contact_id) selected @endif >
{{$contact->firstname}}
</option>
@endforeach
@endforeach