【问题标题】:How to change url in pagination?如何更改分页中的url?
【发布时间】:2019-05-02 15:43:19
【问题描述】:

在我的 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

?

谢谢!

【问题讨论】:

标签: laravel-5


【解决方案1】:

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

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

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

withPath 方法允许你自定义使用的 URI 生成链接时的分页器。例如,如果您想要 分页器生成链接,如 http://example.com/custom/url?page=N,您应该将 custom/url 传递给 withPath 方法

【讨论】:

    猜你喜欢
    • 2013-05-04
    • 2011-06-30
    • 2014-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多