3

In my Laravel 5.7 app I have news page

http://mysite/all_news

with pagination implementation as:

$newsList = PageContent
    ::select(\DB::raw(' page_contents.*, users.username'))
    ->getByPageType( 'N' )
    ->getByPublished( true )
    ->orderBy('created_at', 'desc')
    ->join(\DB::raw('users '), \DB::raw('users.id'), '=', \DB::raw('page_contents.creator_id'))
    ->paginate( 4 , null, null, $page)
    ->onEachSide();

and route defined as :

Route::get('all_news', array(
    'as'      => 'all_news',
    'uses'    => 'PageController@all_news'
));

and in view I show pagination :

{{ $newsList->appends([])->links() }}

But rendered links in pagination looks like(and how to render them ?):

http://mysite/all_news?=2

How to make urls look like

http://mysite/all_news/2

?

Thanks!

1
  • 2
    Have a look at this answer Commented Nov 30, 2018 at 14:43

1 Answer 1

3

Take a look at this: https://laravel.com/docs/5.7/pagination#displaying-pagination-results

Specifically: "Customizing The Paginator URI":

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

The withPath method allows you to customize the URI used by the paginator when generating links. For example, if you want the paginator to generate links like http://example.com/custom/url?page=N, you should pass custom/url to the withPath method

Sign up to request clarification or add additional context in comments.

1 Comment

The solution from the linked manual in this answer doesn't address the problem the thread starter mentioned, namely to remove the page number from the query string and make the page number part of the URL http://mysite/all_news/2. Anyone ending up here should check @Remul 's link in the comment above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.