Home > other >  how could I use 2 foreach in Laravel using 1 view
how could I use 2 foreach in Laravel using 1 view

Time:02-10

<h2 >الكورس الاول</h2>
<div >

    @foreach ($data as $item)
    <div >
        <div >

            <h5 >{{$item->name}}</h5>
            <hr>
            <a href="/lectures" >show lectures</a>
        </div>
    </div>
    @endforeach

    <h2 >الكورس الثاني</h2>

    @foreach ($data2 as $item)
    <div >
        <div >

            <h5 >{{$item->name}}</h5>
            <hr>
            <a href="/lectures" >show lectures</a>
        </div>
    </div>
    @endforeach
</div>

CodePudding user response:

If I'm understanding your question correctly.

You can nest @foreach statements like so

@foreach ($list1 as $item1)
     ...
     @foreach ($list2 as $item2)
          ...
     @endforeach
     ...
@endforeach

You would obviously want to use better names for the variables than in my sample. You do not need to have additional statements between the loops. The "..." is there to show you can.

CodePudding user response:

@foreach ($data as $item)
     {{ $item->name }} 

     @foreach ($data2 as $item2)
          {{ $item2->name }} 
     @endforeach
     
@endforeach
  •  Tags:  
  • Related