diff --git a/.github/workflows/tests-php8.yml b/.github/workflows/tests-php8.yml index ebbf214..6e147c0 100644 --- a/.github/workflows/tests-php8.yml +++ b/.github/workflows/tests-php8.yml @@ -17,11 +17,11 @@ jobs: strategy: matrix: - laravel: ['8.*','9.*','10.*'] - php: [8.0, 8.1] + laravel: ['10.*', '11.*'] + php: [8.1, 8.2] exclude: - - laravel: '10.*' - php: 8.0 + - laravel: '11.*' + php: 8.1 fail-fast: false name: Laravel ${{ matrix.laravel }}, PHP ${{ matrix.php }} diff --git a/README.md b/README.md index d0e71c5..523aa6a 100644 --- a/README.md +++ b/README.md @@ -48,9 +48,55 @@ $ composer require suarez/laravel-utm-parameter ### Middleware +#### Laravel 11 + +Open the `bootstrap/app.php` file and append the `UtmParameters::class` inside the web-group + +```php +# Laravel 11 +return Application::configure(basePath: dirname(__DIR__)) + ... + ->withMiddleware(function (Middleware $middleware) { + $middleware->web(append: [ + Suarez\UtmParameter\Middleware\UtmParameters::class, + /* ... keep the existing middleware here */ + ]); + }) + ... +``` + +To enable UTM-Parameters only for certain requests to your site, add a new alias. + +```php +# Laravel 11 +use Suarez\UtmParameter\Middleware\UtmParameters; + +->withMiddleware(function (Middleware $middleware) { + $middleware + ->alias([ + /* ... keep the existing mappings here */ + 'utm-parameters' => UtmParameters::class, + ]) + ->web(append: [ + /* ... keep the existing mappings here */ + UtmParameters::class + ]); +}) +``` + +To apply UTM-Parameters to specific routes, use the following middleware: `utm-parameters` + +```php +Route::middleware('utm-parameters') + ->get('langing-page/{slug}', 'LandingPageController@show'); +``` + +#### Laravel 10 + Open the `app/Http/Kernel.php` file and add a new item to the `web` middleware group: ```php +# Laravel 10 and below protected $middlewareGroups = [ 'web' => [ /* ... keep the existing middleware here */ @@ -59,16 +105,10 @@ protected $middlewareGroups = [ ]; ``` -To enable UTM-Parameters only for certain requests to your site, add a new mapping to either the `routeMiddleware` (Laravel 9) or the `middlewareAliases` (Laravel 10) Array. +To enable UTM-Parameters only for certain requests to your site, add a new mapping to the `middlewareAliases` Array. ```php -# Laravel 9 and below -protected $routeMiddleware = [ - /* ... keep the existing mappings here */ - 'utm-parameters' => \Suarez\UtmParameter\Middleware\UtmParameters::class, -]; - -# Laravel 10 +# Laravel 10 and below protected $middlewareAliases = [ /* ... keep the existing mappings here */ 'utm-parameters' => \Suarez\UtmParameter\Middleware\UtmParameters::class, @@ -101,7 +141,6 @@ If you need to retrieve certain UTM parameters, use `get_utm('source|medium|camp ``` ```php - // Some Task in your Class public function someTask() { diff --git a/composer.json b/composer.json index 298d167..7a0f543 100644 --- a/composer.json +++ b/composer.json @@ -11,13 +11,13 @@ } ], "require": { - "php": "^8.0|^8.1", - "illuminate/support": "^8.0|^9.0|^10.0", - "illuminate/contracts": "^8.0|^9.0|^10.0" + "php": "^8.1|^8.2", + "illuminate/support": "^10.0|^11.0", + "illuminate/contracts": "^10.0|^11.0" }, "require-dev": { - "nunomaduro/collision": "^5.10|^6.0|^7.0", - "orchestra/testbench": "^6.22|^7.0|^8.0", + "nunomaduro/collision": "^7.0|^8.1", + "orchestra/testbench": "^7.0|^8.0|^9.0", "phpunit/phpunit": "^9.5|^10.0", "friendsofphp/php-cs-fixer": "^3.0" }, diff --git a/phpunit.xml b/phpunit.xml index 0b89ed7..a33bf82 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,13 +1,13 @@ - - - - ./src - - + ./tests + + + ./src + + diff --git a/src/Middleware/UtmParameters.php b/src/Middleware/UtmParameters.php index 1f4302c..c4da511 100644 --- a/src/Middleware/UtmParameters.php +++ b/src/Middleware/UtmParameters.php @@ -4,7 +4,6 @@ use Closure; use Illuminate\Http\Request; -use Illuminate\Http\Response; use Suarez\UtmParameter\UtmParameter; class UtmParameters @@ -32,7 +31,7 @@ public function handle(Request $request, Closure $next) * @param \Illuminate\Http\Request $request * @param \Illuminate\Http\Response $response * - * @return bool + * @return \Illuminate\Http\Request */ protected function shouldAcceptUtmParameter(Request $request) { diff --git a/src/UtmParameter.php b/src/UtmParameter.php index 816eef8..7c21669 100644 --- a/src/UtmParameter.php +++ b/src/UtmParameter.php @@ -21,7 +21,7 @@ public function __construct($parameters = []) /** * Bootstrap UtmParameter. * - * @param array|null $parameters + * @param array|string|null $parameters * * @return UtmParameter */