Support the ongoing development of Laravel.io →
Requests Views Forms
Last updated 2 years ago.
0

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));
}
Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

Still not working

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.