Does the number at end of URL change?
http://domain.com/employess/?page=2 <=
I have added pagination as follows. But all the pages display the same content. Think that there are 8 records in the employee table. When I added the below code to my laravel project, on the first page it displays all 8 records and on the second page also it displays the same 8 records.
It doesn't break the first 5 records to the first page and last 3 records to the second page.
controller
public function all()
{
$data = DB::table('employees')->paginate(5);
$employeeshow = employee::all()->toArray();
return view('employee.index', compact('employeeshow', 'data'));
}
index.blade.php
<div>
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
@foreach($employeeshow as $row)
<tr>
<td>{{$row['firstname']}}</td>
<td>{{$row['lastname']}}</td>
</tr>
@endforeach
</table>
{{ $data->links() }}
</div>
I want to display first 5 records on first page, next 5 records in the second page likewise. Thank you
@mayuri0606 Change it to this
public function all()
{
$employees = employee::paginate(5);
return view('employee.index', compact('employees'));
}
<div>
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
@foreach($employees as $employee)
<tr>
<td>{{ $employee->firstname }}</td>
<td>{{ $employee->lastname }}</td>
</tr>
@endforeach
</table>
{{ $employees->links() }}
</div>
And why do you have you model as employee lowercase?
Please or to participate in this conversation.