Skip to content

Commit

Permalink
#16: adjusted docs according to Laravel 11.x project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
klimov-paul committed Jul 11, 2024
1 parent eb8b079 commit 14dec57
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 52 deletions.
64 changes: 32 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ in 'bootstrap/app.php' file of regular Laravel application. For example:
```php
<?php

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

$app->singleton(
Illuminate\Contracts\Http\Kernel::class,
App\Http\Kernel::class
);
// ...
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

$app = Application::configure(basePath: dirname(__DIR__))
->withRouting(
// ...
)
->withMiddleware(function (Middleware $middleware) {
// ...
})
// ...
->create();

$app->register(new Illuminatech\UrlTrailingSlash\RoutingServiceProvider($app)); // register trailing slashes routing

Expand All @@ -65,30 +69,26 @@ middleware to your HTTP kernel. For example:
```php
<?php

namespace App\Http;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

$app = Application::configure(basePath: dirname(__DIR__))
->withRouting(
// ...
)
->withMiddleware(function (Middleware $middleware) {
$middleware->prependToGroup('web', Illuminatech\UrlTrailingSlash\Middleware\RedirectTrailingSlash::class); // enable automatic redirection on incorrect URL trailing slashes
// probably you do not need trailing slash redirection anywhere besides public web routes,
// thus there is no reason for addition its middleware to other groups, like API
// ...
})
// ...
->create();

use Illuminate\Foundation\Http\Kernel as HttpKernel;
$app->register(new Illuminatech\UrlTrailingSlash\RoutingServiceProvider($app)); // register trailing slashes routing

class Kernel extends HttpKernel
{
protected $middlewareGroups = [
'web' => [
\Illuminatech\UrlTrailingSlash\Middleware\RedirectTrailingSlash::class, // enable automatic redirection on incorrect URL trailing slashes
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// ...
],

'api' => [
// probably you do not need trailing slash redirection anywhere besides public web routes,
// thus there is no reason for addition its middleware to other groups, like API
'throttle:60,1',
// ...
],
];
// ...
}
return $app;
```

**Heads up!** Make sure you do not have any trailing slash redirection mechanism at the server configuration level, which
Expand Down Expand Up @@ -174,7 +174,7 @@ echo route('categories.show', [1]); // outputs: 'http://example.com/categories/1
```

You can control trailing slash presence per each resource route using options 'trailingSlashOnly' and 'trailingSlashExcept' options.
These ones behave in similar to regular 'only' and 'except', specifying list of resource controller methods, which should
These behave in similar to regular 'only' and 'except', specifying list of resource controller methods, which should
or should not have a trailing slash in their URL. For example:

```php
Expand Down
27 changes: 16 additions & 11 deletions src/Middleware/RedirectTrailingSlash.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,26 @@
* This middleware should be assigned to the route group, which should maintain SEO, for example:
*
* ```php
* namespace App\Http;
* <?php
*
* use Illuminate\Foundation\Http\Kernel as HttpKernel;
* use Illuminate\Foundation\Application;
* use Illuminate\Foundation\Configuration\Exceptions;
* use Illuminate\Foundation\Configuration\Middleware;
*
* class Kernel extends HttpKernel
* {
* protected $middlewareGroups = [
* 'web' => [
* \Illuminatech\UrlTrailingSlash\Middleware\RedirectTrailingSlash::class,
* // ...
* ],
* $app = Application::configure(basePath: dirname(__DIR__))
* ->withRouting(
* $middleware->prependToGroup('web', Illuminatech\UrlTrailingSlash\Middleware\RedirectTrailingSlash::class); // enable automatic redirection on incorrect URL trailing slashes
* // ...
* ];
* )
* ->withMiddleware(function (Middleware $middleware) {
* // ...
* })
* // ...
* }
* ->create();
*
* $app->register(new Illuminatech\UrlTrailingSlash\RoutingServiceProvider($app)); // register trailing slashes routing
*
* return $app;
* ```
*
* > Tip: there is no point to assign this middleware to the routes, which are not indexed by search engines, like API.
Expand Down
22 changes: 13 additions & 9 deletions src/RoutingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@
* ```php
* <?php
*
* $app = new Illuminate\Foundation\Application(
* $_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
* );
* use Illuminate\Foundation\Application;
* use Illuminate\Foundation\Configuration\Exceptions;
* use Illuminate\Foundation\Configuration\Middleware;
*
* $app->singleton(
* Illuminate\Contracts\Http\Kernel::class,
* App\Http\Kernel::class
* );
* // ...
* $app = Application::configure(basePath: dirname(__DIR__))
* ->withRouting(
* // ...
* )
* ->withMiddleware(function (Middleware $middleware) {
* // ...
* })
* // ...
* ->create();
*
* $app->register(new Illuminatech\UrlTrailingSlash\RoutingServiceProvider($app));
* $app->register(new Illuminatech\UrlTrailingSlash\RoutingServiceProvider($app)); // register trailing slashes routing
*
* return $app;
* ```
Expand Down

0 comments on commit 14dec57

Please sign in to comment.