How to display specified number of records on web page?
Like : Items per page: 25 | 50 | 75 |100 If I select 25 then 25 records should be displayed.. I want this in laravel 5.5.. can anyone help me?
There is no default functionality for per page in Laravel till 5.7. So, you need to add some custom functionality.
Use get parameter where you paginate your record like this:
public function get_users(Request $request) {
return view('users', Users::paginate($request->get('per_page', 25)));
}
And send per_page parameter from view.
There are several ways to send per_page parameter from view.
I am using LaravelCollective 5.4 for this purpose https://laravelcollective.com/docs/5.4/html#drop-down-lists:
{!! Form::open([ 'url' => route('users'), 'method' => 'get' ]) !!}
{!! Form::select( 'per_page', [ '25' => '25', '50' => '50', '75' => '75', '100' => '100'], '25', array('onchange' => "submit()") ) !!}
{!! Form::close() !!}
->paginate(75). The Pagination Docs are pretty clear about that.yourapp.com/users?perPage=100and in your controller action just fetch that from the requestUsers::paginate(request()->get('perPage', 25);. This will get the100value from the request and if noperPageparamater was passed, it will default to25. You also might want to inject the request into your controller action method (not use therequest()helper) and in order to do that you might want to read the HTTP Requests Docs.