承接 trinityrank/tailing-slash 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

trinityrank/tailing-slash

Composer 安装命令:

composer require trinityrank/tailing-slash

包简介

TailingSlash adds '/' at the end of urls

README 文档

README

Latest Version on Packagist

Adds URL formatting and redirection with trailing slash to Laravel framework.

Installation

Step 1: Install package

To get started with Laravel Trailing Slash, use Composer command to add the package to your composer.json project's dependencies:

composer require trinityrank/tailing-slash

Step 2: Service Provider

After installing the package, register Trinityrank\TailingSlash\RoutingServiceProvider in your config/app.php.

    'providers' => [
        /*
        * Package Service Providers...
        */
        // ...
        Trinityrank\TailingSlash\RoutingServiceProvider::class
        // ...
    ],
    'aliases' => [
        // ...
        'UrlGenerator' => Trinityrank\TailingSlash\UrlGenerator::class,
        // ...
    ].

Step 3: Routes

    Route::get('/', function () {
        return view('welcome');
    });

    Route::get('about-us/', function () {
        return view('about');
    });

Usage

Whenever you use some Laravel redirect function, tailing slash ("/") will be applied to the end of url.

    return redirect('about/');

    return back()->withInput();

    return redirect()->route('post', ['id' => 1]);

    return redirect()->action('IndexController@about');

Notice

There is a problem with overriding Laravel Paginator and LengthAwarePaginator classes. So, every time you use paginate() method on your models, query builders etc., you must set current path for pagination links. Example:

    $posts = Text::where('is_active', 1)->paginate();
    $posts->setPath(URL::current());

    $posts->links();

Pagiantion

  • Use this method to format pagination links on your blade component (tailwind.blade.php) and also use this for canonical links (check your cleanCanonicalURL in BaseController)
    UrlGenerator::paginationLinks($url)
  • On your 'web.php' add page route for pagination. Use same controller and same method as you will use for normal archive page (just path is changed)
  • ADD ABOVE THE REGILAR METHOD (not below)
    // Paginate emethod
    Route::get('{slug}/page/{page}', [FrontendController::class, 'resolve'])->name('resolve');
    // Your regulat method
    Route::get('{slug}', [FrontendController::class, 'resolve'])->name('resolve');
  • In controller just add couple of thinks things
    • use UrlGenerator on top of the document
    • In method add new optional param $pageNumber
    • Add UrlGenerator::paginationCheck method at the beginning of the method
        use Trinityrank\TailingSlash\UrlGenerator;
        // ...
        public function method($slug, $pageNumber = null){
            // This add at the beginning of the method
            UrlGenerator::paginationCheck($pageNumber);
            // ...
        }
  • Method paginationCheck has second optional paramether if default paginate keyword is not page

统计信息

  • 总下载量: 261
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-09-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固