发布于 5年前

Laravel 分页链接 url 伪静态 rewrite

能够解决部分 seo 和强迫症同学的需求

  • Route

    Route::get('posts/page/{page?}', function ($page = 1) {
    Request::merge(['page' => $page]);
    $posts = Post::orderBy('id', 'DESC')->paginate(3);
    
    return view('post.index', ['posts' => $posts]);
    });
  • View
    • quick and dirty
      {!! preg_replace("~(/page/\d+)?\?page=~", '/page/', $posts->render()) !!}
    • 追求优雅的同学还是自己写个 Presenter 替换默认的 Presenter 吧
©2020 edoou.com   京ICP备16001874号-3