Haruka
Haruka

Reputation: 13

How to correctly return all items in a laravel collection

Currently trying to display a list of all objects in a collection subfleets I am using the get command but only returns the first object:

<tr>
    <td>@lang('flights.subfleets')</td>
    <td>{{ $flight->subfleets->get(0)->name }}</td>
</tr>

Upvotes: 0

Views: 75

Answers (2)

Rostik Hvostik
Rostik Hvostik

Reputation: 59

See https://laravel.com/docs/5.8/blade#loops

@foreach($flight->subfleets as $subFleet)
   <tr>
      <td>{{ $subFleet->name }}</td>
   </tr>
@endforeach

Upvotes: 1

Poldo
Poldo

Reputation: 1932

You should iterate $flight->subfleets->get() using @foreach;

@foreach($flight->subfleets->get() as $subFleet)
   <tr>
      <td>{{ $subFleet->name }}</td>
   </tr>
@endforeach

Upvotes: 0

Related Questions