php - Laravel Blade Foreach only shows 10 items
Solution:
If the reason you're trying to print 10 instead of 12 is so you can paginate, you should use Laravel's paginator:
$candidates = Candidate::all()->where('vacancy_id', $id)->paginate(10);
Answer
Solution:
Try this:
@foreach($candidates as $key => $candidate)
@if($key < 10)
{{$candidate->value}}
@endif
@endforeach
Answer
Solution:
There is a problem with your loop, if you use all() no need to use the where condition, with where condition use get()
$candidates = Candidate::where('vacancy_id', $id)->get();
Your Loop
@foreach($candidates AS $candidate_key => $candidate_value)
@if($candidate_key <= 9)
{{ $candidate_value->vacancy_id }}
@endif
@endforeach
Answer
Solution:
why not just do it?
@foreach($candidates as $team)
{{$loop->iteration}}
@endforeach
$loop->iteration: The current loop iteration (starts at 1).
more information here: https://laravel.com/docs/8.x/blade.
Answer
Solution:
try this one
$candidates = Candidate::where('vacancy_id', $id)->get();
Source