如何在分页中更改url?

时间:2018-11-30 13:16:07

标签: laravel-5

在我的Laravel 5.7应用中,我有新闻页面

http://mysite/all_news

分页实现为:

$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();

和定义为的路由:

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

鉴于此,我显示了分页:

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

但是分页中呈现的链接看起来像(以及如何呈现它们?):

http://mysite/all_news?=2

如何使网址看起来像

http://mysite/all_news/2

谢谢!

1 个答案:

答案 0 :(得分:0)

看看这个: https://laravel.com/docs/5.7/pagination#displaying-pagination-results

具体来说: “自定义分页器URI”:

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

withPath方法可让您自定义   分页器在生成链接时。例如,如果您想要   分页器来生成像   http://example.com/custom/url?page=N,您应该将自定义/网址传递给   withPath方法

相关问题