I am trying to add the class 'active' if tis the first item in a foreach but I keep getting a parse error? I am using Laravel and Blade, this is how I pass $members
public function getView()
{
Cache::remember('members.members', 1, function() {
return Player::orderBy('id', 'DESC')->where('display_member', '=', '1')->limit(10)->get();
});
return view('frontend.members')->withMembers(Cache::get('members.members'));
}
Parse error: syntax error, unexpected 'endforeach' (T_ENDFOREACH),
expecting elseif (T_ELSEIF) or else (T_ELSE) or endif (T_ENDIF)
@if ($members->count() > 0)
@foreach ($members as $key => $member)
{{ $member->username }}
Personal Website: {{ $member->personal_website }}
Last Login: 1st January, 2017
@endforeach
@endif
Answer
If your version laravel 5.3:
@foreach($array as $key => $value)
@if ($loop->first)
...
@endif
@endforeach
No comments:
Post a Comment