@@ -41,15 +41,19 @@ in 'bootstrap/app.php' file of regular Laravel application. For example:
4141``` php
4242<?php
4343
44- $app = new Illuminate\Foundation\Application(
45- $_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
46- );
47-
48- $app->singleton(
49- Illuminate\Contracts\Http\Kernel::class,
50- App\Http\Kernel::class
51- );
52- // ...
44+ use Illuminate\Foundation\Application;
45+ use Illuminate\Foundation\Configuration\Exceptions;
46+ use Illuminate\Foundation\Configuration\Middleware;
47+
48+ $app = Application::configure(basePath: dirname(__DIR__))
49+ ->withRouting(
50+ // ...
51+ )
52+ ->withMiddleware(function (Middleware $middleware) {
53+ // ...
54+ })
55+ // ...
56+ ->create();
5357
5458$app->register(new Illuminatech\UrlTrailingSlash\RoutingServiceProvider($app)); // register trailing slashes routing
5559
@@ -65,30 +69,26 @@ middleware to your HTTP kernel. For example:
6569``` php
6670<?php
6771
68- namespace App\Http;
72+ use Illuminate\Foundation\Application;
73+ use Illuminate\Foundation\Configuration\Exceptions;
74+ use Illuminate\Foundation\Configuration\Middleware;
75+
76+ $app = Application::configure(basePath: dirname(__DIR__))
77+ ->withRouting(
78+ // ...
79+ )
80+ ->withMiddleware(function (Middleware $middleware) {
81+ $middleware->prependToGroup('web', Illuminatech\UrlTrailingSlash\Middleware\RedirectTrailingSlash::class); // enable automatic redirection on incorrect URL trailing slashes
82+ // probably you do not need trailing slash redirection anywhere besides public web routes,
83+ // thus there is no reason for addition its middleware to other groups, like API
84+ // ...
85+ })
86+ // ...
87+ ->create();
6988
70- use Illuminate\Foundation\Http\Kernel as HttpKernel;
89+ $app->register(new Illuminatech\UrlTrailingSlash\RoutingServiceProvider($app)); // register trailing slashes routing
7190
72- class Kernel extends HttpKernel
73- {
74- protected $middlewareGroups = [
75- 'web' => [
76- \Illuminatech\UrlTrailingSlash\Middleware\RedirectTrailingSlash::class, // enable automatic redirection on incorrect URL trailing slashes
77- \App\Http\Middleware\EncryptCookies::class,
78- \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
79- \Illuminate\Session\Middleware\StartSession::class,
80- // ...
81- ],
82-
83- 'api' => [
84- // probably you do not need trailing slash redirection anywhere besides public web routes,
85- // thus there is no reason for addition its middleware to other groups, like API
86- 'throttle:60,1',
87- // ...
88- ],
89- ];
90- // ...
91- }
91+ return $app;
9292```
9393
9494** Heads up!** Make sure you do not have any trailing slash redirection mechanism at the server configuration level, which
@@ -174,7 +174,7 @@ echo route('categories.show', [1]); // outputs: 'http://example.com/categories/1
174174```
175175
176176You can control trailing slash presence per each resource route using options 'trailingSlashOnly' and 'trailingSlashExcept' options.
177- These ones behave in similar to regular 'only' and 'except', specifying list of resource controller methods, which should
177+ These behave in similar to regular 'only' and 'except', specifying list of resource controller methods, which should
178178or should not have a trailing slash in their URL. For example:
179179
180180``` php
0 commit comments