Skip to content

Commit

Permalink
Added Laravel 11 Support (#7)
Browse files Browse the repository at this point in the history
* - added blade directives: `hasUtm` and `hasNotUtm`

* - fixed code styling

* - updated to laravel 11

* - updated composer.json

* - updated github actions

* - updated github actions

* - update

* - fix
  • Loading branch information
toni-suarez committed Mar 13, 2024
1 parent 5b0e327 commit 57a3913
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 27 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/tests-php8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
57 changes: 48 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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,
Expand Down Expand Up @@ -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()
{
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
12 changes: 6 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false">
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
3 changes: 1 addition & 2 deletions src/Middleware/UtmParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Closure;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Suarez\UtmParameter\UtmParameter;

class UtmParameters
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/UtmParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct($parameters = [])
/**
* Bootstrap UtmParameter.
*
* @param array|null $parameters
* @param array|string|null $parameters
*
* @return UtmParameter
*/
Expand Down

0 comments on commit 57a3913

Please sign in to comment.