1 year ago

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

Posted 1 year 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)

         <td><a href="{{$fbr->File}}" target="_blank">{{$fbr->F_Number}}</a></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><a href="{{$fbr->data}}">{{$fbr->number1}}</a></td>

          <td><a href="">all is well</a></td>



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.