intrip / laravel-authentication-acl

Laravel authentication and ACL admin panel package based on sentry
287 stars 110 forks source link

Pagination #154

Open jicao opened 7 years ago

jicao commented 7 years ago

Hello,

(First, GREAT WORK ! Thanks)

I can't get the pagination to work...

When I put "users_per_page" => 1, and then insert 2 users into my app db, when I want to click on the arrow (It detects tha pagination is needed!) to go to next page, it links me to http://myapp.com/?page=2 and even if I manually put "http://myapp.com/admin/users/list?page=2", there is no error but it's the "first page" with the first user that is shown. I can't see the second one.

Any help ?

Thanks

jicao commented 7 years ago

Hello,

Did anyone has the same trouble or it's just me ?

Thanks

leekul commented 7 years ago

Having the same issue. Pagination doesnt work for user list and the list doesn't recognize more than "users_per_page" value. Even if you add more users, the dashboard would only show total of "users_per_page"-value users. The users table in DB does have all the users added. Like @jicao mentioned, clicking the next arrow only takes you to the homepage. Even manually editing the url would only return the first page.

intrip commented 7 years ago

What version or Laravel are you using?

leekul commented 7 years ago

Laravel 5.3.30

leekul commented 7 years ago

Update: Was able to fix the pagination issue on the user list page by using paginate method on the return of all() in app/Authentication/Repository/UserRepositorySearchFilter.php. Havent tested to ensure any other regression exists. Not quite sure why the array_unique is used there either since user emails will be unique as per DB. So I basically replaced:

    `
    $users = $q->get()->all();
    $user_emails = array_flip(array_map((function ($element)
    {
        return $element->email;
    }), $users));
    $users_emails_unique = array_unique($user_emails);
    $results = array_only($users, array_values($users_emails_unique));

    return new Paginator($results, $this->per_page);`

with

return $q->paginate($this->per_page);

Not the best solution i guess, but it works for the time being. Dashboard values are still dependent on the values set in acl_base though.

jicao commented 7 years ago

FYI : # php artisan --version Laravel Framework version 5.3.28

This solved my problem ! Don't know why you're saying it's not the best solution but working for me right now :)

Thanks.

leekul commented 7 years ago

@jicao : I didnt test the other usages of the function to make sure something else didn't stop working. ;) Thats why I mentioned that its probably not the best solution. But yes, the pagination on the user list does work after this change.