trinityrank/tailing-slash
Composer 安装命令:
composer require trinityrank/tailing-slash
包简介
TailingSlash adds '/' at the end of urls
README 文档
README
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
cleanCanonicalURLinBaseController)
UrlGenerator::paginationLinks($url)
- On your 'web.php' add page route for pagination. Use same
controllerand samemethodas you will use for normal archive page (justpathis 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
UrlGeneratoron top of the document - In method add new optional param
$pageNumber - Add
UrlGenerator::paginationCheckmethod at the beginning of the method
- use
use Trinityrank\TailingSlash\UrlGenerator; // ... public function method($slug, $pageNumber = null){ // This add at the beginning of the method UrlGenerator::paginationCheck($pageNumber); // ... }
- Method
paginationCheckhas second optional paramether if default paginate keyword is notpage
统计信息
- 总下载量: 261
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-09-29