amrnn90 / laravel-cursor-paginator

Cursor pagination for Laravel
MIT License
19 stars 7 forks source link

Unable to change path in url #6

Closed jaiselrahman closed 5 years ago

jaiselrahman commented 5 years ago

It seems that $this->options value is not passed to CursorPaginator, which makes it unable to change the path in navigation url.

https://github.com/amrnn90/laravel-cursor-paginator/blob/294f340c79b14af72d85b9f3e17ef9579c5774f1/src/Macro.php#L12-L25

And also it would be great to customise the default path in config file.

amrnn90 commented 5 years ago

I decided to leave that to Laravel's AbstractPaginator since it already takes care of it, but I guess I forgot to delete some code in CursorPaginator's constructor which might've led to some confusion.

If you want to to change the path, call the setPath() method on the paginator instance:

return Post::orderBy('id')
  ->cursorPaginate()
  ->setPath(url('/somewhere'));

To have a default path, just register a path resolver in your AppServiceProvider.php for example:

use Amrnn\CursorPaginator\CursorPaginator;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        CursorPaginator::currentPathResolver(function () {
            return url('/default-path');
        });
    }
}
jaiselrahman commented 5 years ago

Yes got confused by this line https://github.com/amrnn90/laravel-cursor-paginator/blob/294f340c79b14af72d85b9f3e17ef9579c5774f1/src/CursorPaginator.php#L31-L33 Now I got it, Thanks, I am closing this issue now.