How to create custom pagination link?

Right now i have this link on paginate :

www.test.com/search/filter?page=1

www.test.com/search/filter?page=2

and what i want is this:
www.test.com/search?search=&page=2 and so on

Right now i have this:

{!! $properties->appends(['toggle' => Request::get('toggle'), 'search' => Request::get('search')])->render() !!}

How can i change this to have route like this what i want?

i found this:

Route::get('users', function () {
    $users = AppUser::paginate(15);

    $users->setPath('custom/url');

    //
});

But problem is that i use one function for multiple stuff so i can not set path in controller.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can keep your existing query like this. you can define one function in your controller

public function getExistingQueryParams()
{
    $existingQueryParams = [];

    foreach (request()->all() as $key => $value)
    {
        if ($key != 'page')
        {
            $existingQueryParams[$key] = urldecode($value);
        }
    }

    return $existingQueryParams;
}

In your controller’s function which is returning the view call this function.
$existingQuery = $this->getExistingQueryParams();

Pass this variable in your view and in your view you can use it like this
{{ $propertiers->appends($existingQuery)->links() }}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x