Skip to content

Commit df048e7

Browse files
author
xinningsu
committed
add readme
1 parent 9b11143 commit df048e7

File tree

2 files changed

+145
-1
lines changed

2 files changed

+145
-1
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Thomas.Su
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 124 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,124 @@
1-
# laravel-route-trailing-slash
1+
# Laravel route trailing slash
2+
3+
Let laravel route work as exactly as how we define it including the trailing slash.
4+
5+
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
6+
[![Build Status](https://api.travis-ci.org/xinningsu/laravel-route-trailing-slash.svg?branch=master)](https://travis-ci.org/xinningsu/laravel-route-trailing-slash)
7+
[![Coverage Status](https://coveralls.io/repos/github/xinningsu/laravel-route-trailing-slash/badge.svg?branch=master)](https://coveralls.io/github/xinningsu/laravel-route-trailing-slash)
8+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/xinningsu/laravel-route-trailing-slash/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/xinningsu/laravel-route-trailing-slash)
9+
[![Code Intelligence Status](https://scrutinizer-ci.com/g/xinningsu/laravel-route-trailing-slash/badges/code-intelligence.svg?b=master)](https://scrutinizer-ci.com/g/xinningsu/laravel-route-trailing-slash)
10+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xinningsu_laravel-route-trailing-slash&metric=alert_status)](https://sonarcloud.io/dashboard?id=xinningsu_laravel-route-trailing-slash)
11+
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=xinningsu_laravel-route-trailing-slash&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=xinningsu_laravel-route-trailing-slash)
12+
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=xinningsu_laravel-route-trailing-slash&metric=security_rating)](https://sonarcloud.io/dashboard?id=xinningsu_laravel-route-trailing-slash)
13+
[![Maintainability](https://api.codeclimate.com/v1/badges/18669386ce65532b228f/maintainability)](https://codeclimate.com/github/xinningsu/laravel-route-trailing-slash/maintainability)
14+
15+
# Background
16+
17+
Currently when we define a route, Laravel will trim all the tailing slashes, output the route url without any tailing slash. When we access an url with trailing slashes, Laravel also will trim them. That makes the tailing slashes meaningless, sometimes it's quite annoying.
18+
19+
20+
## Define a route like this
21+
22+
```php
23+
use App\Http\Controllers\PartnersController;
24+
25+
Route::get('/partners/', [PartnersController::class, 'index'])->name('partners');
26+
```
27+
28+
29+
### Current behavior
30+
31+
| URL | Status |
32+
| ------------- |------------- |
33+
| [https://laravel.com/partners](https://laravel.com/partners) | 200 |
34+
| [https://laravel.com/partners/](https://laravel.com/partners/) | 200 |
35+
| [https://laravel.com/partners////](https://laravel.com/partners////) | 200 |
36+
37+
38+
### Expected behavior
39+
40+
| URL | Status |
41+
| ------------- |------------- |
42+
| [https://laravel.com/partners](https://laravel.com/partners) | 404 |
43+
| [https://laravel.com/partners/](https://laravel.com/partners/) | 200 |
44+
| [https://laravel.com/partners////](https://laravel.com/partners////) | 404 |
45+
46+
47+
## Output the route url
48+
49+
```php
50+
echo route('partners');
51+
52+
```
53+
54+
### Current behavior
55+
56+
`https://laravel.com/partners`
57+
58+
### Expected behavior
59+
60+
`https://laravel.com/partners/`
61+
62+
63+
## Pagination render
64+
65+
Using database query builder or LengthAwarePaginator/Paginator
66+
67+
### Current behavior
68+
69+
`https://laravel.com/partners?page=2`
70+
71+
### Expected behavior
72+
73+
`https://laravel.com/partners/?page=2`
74+
75+
76+
# Usage
77+
78+
There are two service providers, as the router service provider has to register at the very beginning before laravel http kernel class instantiation, so I can not make it work by Laravel Package Auto-Discovery function. Have to manually add it.
79+
80+
81+
### RoutingServiceProvider
82+
83+
open `bootstrap/app.php`, right after app instantiation
84+
85+
```php
86+
$app = new Illuminate\Foundation\Application(
87+
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
88+
);
89+
90+
```
91+
92+
add
93+
```php
94+
$app->register(Sulao\LRTS\Routing\RoutingServiceProvider::class);
95+
96+
```
97+
98+
### PaginationServiceProvider
99+
100+
Pagination Service Provider has to be added **after** laravel original Pagination Service Provider.
101+
102+
add `Sulao\LRTS\Pagination\PaginationServiceProvider::class` to config/app.php under `providers` element, **after** `Illuminate\Pagination\PaginationServiceProvider::class`
103+
104+
```php
105+
[
106+
Illuminate\Pagination\PaginationServiceProvider::class,
107+
108+
// ...
109+
110+
/*
111+
* Package Service Providers...
112+
*/
113+
Sulao\LRTS\Pagination\PaginationServiceProvider::class,
114+
115+
// ...
116+
];
117+
118+
```
119+
120+
That's it.
121+
122+
# License
123+
124+
[MIT](./LICENSE)

0 commit comments

Comments
 (0)