PHPackages                             xinningsu/laravel-route-trailing-slash - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. xinningsu/laravel-route-trailing-slash

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

xinningsu/laravel-route-trailing-slash
======================================

Let laravel route work as exactly as how we define it including the trailing slash.

V1.0.1(5y ago)1351MITPHPPHP &gt;=5.6

Since Jan 6Pushed 3y ago1 watchersCompare

[ Source](https://github.com/xinningsu/laravel-route-trailing-slash)[ Packagist](https://packagist.org/packages/xinningsu/laravel-route-trailing-slash)[ RSS](/packages/xinningsu-laravel-route-trailing-slash/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

Laravel route trailing slash
============================

[](#laravel-route-trailing-slash)

Let laravel route work as exactly as how we define it including the trailing slash.

[![MIT licensed](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](./LICENSE)[![Build Status](https://camo.githubusercontent.com/3173611b140659a2b4493f3d20b778c3623d6f3b40dacd57e545a9e39d51490e/68747470733a2f2f6170692e7472617669732d63692e6f72672f78696e6e696e6773752f6c61726176656c2d726f7574652d747261696c696e672d736c6173682e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/xinningsu/laravel-route-trailing-slash)[![Coverage Status](https://camo.githubusercontent.com/0600d9b032a5daf0b84cf39376969131bbc0bbb3ca5fcf048bebc5c1adf7c463/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f78696e6e696e6773752f6c61726176656c2d726f7574652d747261696c696e672d736c6173682f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/xinningsu/laravel-route-trailing-slash)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/f2bdc2b9086540e7ae59f5e96af7a8dcd23406aca28bbfeac98fb9ab2bb82fbb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f78696e6e696e6773752f6c61726176656c2d726f7574652d747261696c696e672d736c6173682f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/xinningsu/laravel-route-trailing-slash)[![Code Intelligence Status](https://camo.githubusercontent.com/ca46433ef2864df2cc79c2c798d5cec4c78dd0a5ed3102871ce24215b8dd2a67/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f78696e6e696e6773752f6c61726176656c2d726f7574652d747261696c696e672d736c6173682f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d6173746572)](https://scrutinizer-ci.com/g/xinningsu/laravel-route-trailing-slash)[![Quality Gate Status](https://camo.githubusercontent.com/fa8502538ddf037219e8c290934457db5d23b2dbee8df83d9eb073ba73057bbe/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d78696e6e696e6773755f6c61726176656c2d726f7574652d747261696c696e672d736c617368266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/dashboard?id=xinningsu_laravel-route-trailing-slash)[![Reliability Rating](https://camo.githubusercontent.com/119223b22e0b3c34ccf4796bd24662287e806c2ffadda5a2971d686e1792791a/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d78696e6e696e6773755f6c61726176656c2d726f7574652d747261696c696e672d736c617368266d65747269633d72656c696162696c6974795f726174696e67)](https://sonarcloud.io/dashboard?id=xinningsu_laravel-route-trailing-slash)[![Security Rating](https://camo.githubusercontent.com/5e3f1eff40b1f38ff4dc48443999843769de8ae153858db8432589f9bfc835be/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d78696e6e696e6773755f6c61726176656c2d726f7574652d747261696c696e672d736c617368266d65747269633d73656375726974795f726174696e67)](https://sonarcloud.io/dashboard?id=xinningsu_laravel-route-trailing-slash)[![Maintainability](https://camo.githubusercontent.com/361ad96283dd333822e3e84e5bb44ae5a64eca405f859419aca2d699448fd88e/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f31383636393338366365363535333262323238662f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/xinningsu/laravel-route-trailing-slash/maintainability)

Background
==========

[](#background)

Currently when we define a route, Laravel will trim all the trailing slashes, output the route url without any trailing slash. When we access an url with trailing slashes, Laravel also will trim them. That makes the trailing slashes meaningless, sometimes it's quite annoying.

Define a route like this
------------------------

[](#define-a-route-like-this)

```
use App\Http\Controllers\PartnersController;

Route::get('/partners/', [PartnersController::class, 'index'])->name('partners');
```

Output the route url
--------------------

[](#output-the-route-url)

```
echo route('partners');
```

### Current behavior

[](#current-behavior)

```
https://laravel.com/partners

```

### Expected behavior

[](#expected-behavior)

```
https://laravel.com/partners/

```

Pagination render
-----------------

[](#pagination-render)

Using database query builder or LengthAwarePaginator/Paginator

### Current behavior

[](#current-behavior-1)

```
https://laravel.com/partners?page=2

```

### Expected behavior

[](#expected-behavior-1)

```
https://laravel.com/partners/?page=2

```

Installation
============

[](#installation)

```
composer require xinningsu/laravel-route-trailing-slash

```

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.

### RoutingServiceProvider

[](#routingserviceprovider)

open `bootstrap/app.php`, right after app instantiation

```
$app = new Illuminate\Foundation\Application(
    $_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);
```

add

```
$app->register(Sulao\LRTS\Routing\RoutingServiceProvider::class);
```

### PaginationServiceProvider

[](#paginationserviceprovider)

Pagination Service Provider has to be added **after** laravel original Pagination Service Provider.

add `Sulao\LRTS\Pagination\PaginationServiceProvider::class` to config/app.php under `providers` element, **after** `Illuminate\Pagination\PaginationServiceProvider::class`

```
[
    Illuminate\Pagination\PaginationServiceProvider::class,

    // ...

    /*
    * Package Service Providers...
    */
    Sulao\LRTS\Pagination\PaginationServiceProvider::class,

   // ...
];

```

That's it, now we can generate url with/without trailing slash, same as the definition of route.

Mismatch action
===============

[](#mismatch-action)

Currently Laravel will trim trailing slashes of access url, so no matter how many trailing slashes the url has, it makes no difference.

### Current behavior

[](#current-behavior-2)

URLStatus200200200Now we can custom the mismatch action, such as abort 404, or 301/302 redirect, if route mismatch only because of trailing slash.

### 404 action

[](#404-action)

open `app/Providers/AppServiceProvider.php`, add below line to `register` method

```
\Sulao\LRTS\Routing\Router::$mismatchAction = 404;
```

Now the behavior became

URLStatus404200404### 301/302 action

[](#301302-action)

open `app/Providers/AppServiceProvider.php`, add below line to `register` method

```
\Sulao\LRTS\Routing\Router::$mismatchAction = 301;
```

Now the behavior became

URLStatus301 redirect to 200301 redirect to License
=======

[](#license)

[MIT](./LICENSE)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~9 days

Total

2

Last Release

1949d ago

PHP version history (2 changes)v1.0.0PHP ^5.6 || ^7.0 || ^8.0

V1.0.1PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/7513c529acb322b54c46bef8011275fe734f9d00944c3f3921cebc21c0cd2ed0?d=identicon)[xinningsu](/maintainers/xinningsu)

---

Top Contributors

[![xinningsu](https://avatars.githubusercontent.com/u/7017728?v=4)](https://github.com/xinningsu "xinningsu (2 commits)")

---

Tags

laravellaravel-routelaravel-trailing-slashlaravel-urlrouteroutertrailing-slash

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/xinningsu-laravel-route-trailing-slash/health.svg)

```
[![Health](https://phpackages.com/badges/xinningsu-laravel-route-trailing-slash/health.svg)](https://phpackages.com/packages/xinningsu-laravel-route-trailing-slash)
```

###  Alternatives

[wireui/wireui

TallStack components

1.8k1.3M16](/packages/wireui-wireui)[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4205.3M84](/packages/livewire-volt)[ramonrietdijk/livewire-tables

Dynamic tables for models with Laravel Livewire

21147.4k](/packages/ramonrietdijk-livewire-tables)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
