Hello,
you didn't say what your problem is. I assume you always get 1 item per page.That is because the action is admin/users?pagesize=10.
The routes.php can not find the pagesize inside the url, because it has to be /admin/users/10. It passes null to the getUsers function.
Try to find a way to insert the input into the form action or just give up that pretty url form.
Route::get('admin/users', array('as'=>'admin_users','uses'=>'AdminController@getUsers'));
Controller
public function getUsers(){
$pagesize = Input::get('pagesize');
return View::make('users.admin_users')
->with('users', User::paginate(is_null($pagesize) ? 1 : $pagesize));
}
Thank you for the reply, but I finally managed to solved my problem,after taking advises from a friend, with some javascript. I left the route untouched:
Route::get('admin/users/{pagesize?}', array('as'=>'admin_users','uses'=>'AdminController@getUsers'));
I changed the controller to:
public function getUsers($pagesize = 5){
return View::make('users.admin_users')
->with('pagesize', $pagesize)->with('users', User::paginate($pagesize));
}
And then I change my url structure with the help of some js:
//Form:
<div id="pagination_selection">
{{Form::open(array('route'=>'admin_users','method'=>'get','class' =>'form-inline text-right','id'=>'pagesize_form'))}}
{{Form::label('Display')}}
{{ Form::select('paginator' ,['5' => '5', '15' => '15', '30' => '30', '50' => '50'], $pagesize, array('id'=>'paginator','class' => 'paginator form-control input')) }}
{{Form::close()}}
</div>
//Javascript
<script language='javascript'>
$(function(){
// bind change event to select
$('#paginator').bind('change', function () {
var path = '/admin/';
var pathname = window.location.pathname.split( '/' );
var url = path + pathname[2] + '/' +$(this).val();
if (url) {
window.location = url;
}
return false;
});
});
</script>
I post the solution in case someone else has this problem. Thank you for the answer
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community