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


@foreach ($contacts as $contact)
    @foreach ($rfito as $rfito) 
        <option value="{{$contact->id}}" @if($contact->id == $rfito->contact_id) selected @endif > 

People are also looking for solutions to the problem: amazon sqs - Follow mechanism with php: what strategy to use?


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.

Ask a Question

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.

Similar questions

Find the answer in similar questions on our website.