Skip to content

Commit 14dec57

Browse files
committed
#16: adjusted docs according to Laravel 11.x project structure
1 parent eb8b079 commit 14dec57

File tree

3 files changed

+61
-52
lines changed

3 files changed

+61
-52
lines changed

README.md

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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

176176
You 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
178178
or should not have a trailing slash in their URL. For example:
179179

180180
```php

src/Middleware/RedirectTrailingSlash.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,26 @@
1818
* This middleware should be assigned to the route group, which should maintain SEO, for example:
1919
*
2020
* ```php
21-
* namespace App\Http;
21+
* <?php
2222
*
23-
* use Illuminate\Foundation\Http\Kernel as HttpKernel;
23+
* use Illuminate\Foundation\Application;
24+
* use Illuminate\Foundation\Configuration\Exceptions;
25+
* use Illuminate\Foundation\Configuration\Middleware;
2426
*
25-
* class Kernel extends HttpKernel
26-
* {
27-
* protected $middlewareGroups = [
28-
* 'web' => [
29-
* \Illuminatech\UrlTrailingSlash\Middleware\RedirectTrailingSlash::class,
30-
* // ...
31-
* ],
27+
* $app = Application::configure(basePath: dirname(__DIR__))
28+
* ->withRouting(
29+
* $middleware->prependToGroup('web', Illuminatech\UrlTrailingSlash\Middleware\RedirectTrailingSlash::class); // enable automatic redirection on incorrect URL trailing slashes
3230
* // ...
33-
* ];
31+
* )
32+
* ->withMiddleware(function (Middleware $middleware) {
33+
* // ...
34+
* })
3435
* // ...
35-
* }
36+
* ->create();
37+
*
38+
* $app->register(new Illuminatech\UrlTrailingSlash\RoutingServiceProvider($app)); // register trailing slashes routing
39+
*
40+
* return $app;
3641
* ```
3742
*
3843
* > Tip: there is no point to assign this middleware to the routes, which are not indexed by search engines, like API.

src/RoutingServiceProvider.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,21 @@
1919
* ```php
2020
* <?php
2121
*
22-
* $app = new Illuminate\Foundation\Application(
23-
* $_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
24-
* );
22+
* use Illuminate\Foundation\Application;
23+
* use Illuminate\Foundation\Configuration\Exceptions;
24+
* use Illuminate\Foundation\Configuration\Middleware;
2525
*
26-
* $app->singleton(
27-
* Illuminate\Contracts\Http\Kernel::class,
28-
* App\Http\Kernel::class
29-
* );
30-
* // ...
26+
* $app = Application::configure(basePath: dirname(__DIR__))
27+
* ->withRouting(
28+
* // ...
29+
* )
30+
* ->withMiddleware(function (Middleware $middleware) {
31+
* // ...
32+
* })
33+
* // ...
34+
* ->create();
3135
*
32-
* $app->register(new Illuminatech\UrlTrailingSlash\RoutingServiceProvider($app));
36+
* $app->register(new Illuminatech\UrlTrailingSlash\RoutingServiceProvider($app)); // register trailing slashes routing
3337
*
3438
* return $app;
3539
* ```

0 commit comments

Comments
 (0)