comparing a collection within a colection and fetching the result of inner collection

Posted 10 months ago by thekarm19

i want iterate through a collection in view and show each data in a table and in that table there is a field which needs to check the particular value in another collection passed to the same view ,and if that value in another collection is present then fetch and show it other wise show the previous collection's filed data.

below is the code for the view

collection1 contains 4 items. collection2 contains 3 items.

@foreach($collection1 as $fbr)

      <tr>
         <td>{{$no++}}</td>
         <td>{{$fbr->Country}}</td>
         <td>{{$fbr->Agreement}}</td>
         <td><a href="{{$fbr->File}}" target="_blank">{{$fbr->F_Number}}</a></td>
         <td>{{$fbr->SrNo}}</td>
   
           @foreach($collection2 as $afbr)
        
         @if($fbr->product1 == $afbr->product2 and $fbr->Country == $afbr->Country)

         <td><a href="{{$afbr->data2}}">{{$afbr->number2}}</a></td>
         <td>{{$afbr->Duty}}</td>
         @else
             <td><a href="{{$fbr->data}}">{{$fbr->number1}}</a></td>
         <td>{{$fbr->Duty1}}</td>
         @endif
         @endforeach

          @else
          <td><a href="">all is well</a></td>
          <td>ko</td>
     
         <td>{{$fbr->Description}}</td>

       </tr>



        @endforeach 

in the above code in if else statement the else statement is executing for each loop but i just want to search the value and then display if it present in other collection

Please sign in or create an account to participate in this conversation.