基本上,我正在从StaticPagesController向about.blade.php传递一个变量employees。在循环遍历@foreach时,我希望代码知道是否是最后一个元素,以便输出员工的姓名而不带逗号。这两个方法都不起作用。
@foreach($employees as $employee)
@if($employee == end($employees))
{{ $employee->first_name }} {{ $employee->last_name }}
@else
{{ $employee->first_name }} {{ $employee->last_name }},
@endif
@endforeach
enter code here
2.
@foreach($employees as $employee)
@if($employees->last())
{{ $employee->first_name }} {{ $employee->last_name }}
@else
{{ $employee->first_name }} {{ $employee->last_name }},
@endif
@endforeach