Ad

How To Correctly Return All Items In A Laravel Collection

- 1 answer

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>
Ad

Answer

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

@foreach($flight->subfleets as $subFleet)
   <tr>
      <td>{{ $subFleet->name }}</td>
   </tr>
@endforeach
Ad
source: stackoverflow.com
Ad