Skip to content

Commit 57a3913

Browse files
authored
Added Laravel 11 Support (#7)
* - added blade directives: `hasUtm` and `hasNotUtm` * - fixed code styling * - updated to laravel 11 * - updated composer.json * - updated github actions * - updated github actions * - update * - fix
1 parent 5b0e327 commit 57a3913

File tree

6 files changed

+65
-27
lines changed

6 files changed

+65
-27
lines changed

.github/workflows/tests-php8.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ jobs:
1717

1818
strategy:
1919
matrix:
20-
laravel: ['8.*','9.*','10.*']
21-
php: [8.0, 8.1]
20+
laravel: ['10.*', '11.*']
21+
php: [8.1, 8.2]
2222
exclude:
23-
- laravel: '10.*'
24-
php: 8.0
23+
- laravel: '11.*'
24+
php: 8.1
2525
fail-fast: false
2626

2727
name: Laravel ${{ matrix.laravel }}, PHP ${{ matrix.php }}

README.md

+48-9
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,55 @@ $ composer require suarez/laravel-utm-parameter
4848

4949
### Middleware
5050

51+
#### Laravel 11
52+
53+
Open the `bootstrap/app.php` file and append the `UtmParameters::class` inside the web-group
54+
55+
```php
56+
# Laravel 11
57+
return Application::configure(basePath: dirname(__DIR__))
58+
...
59+
->withMiddleware(function (Middleware $middleware) {
60+
$middleware->web(append: [
61+
Suarez\UtmParameter\Middleware\UtmParameters::class,
62+
/* ... keep the existing middleware here */
63+
]);
64+
})
65+
...
66+
```
67+
68+
To enable UTM-Parameters only for certain requests to your site, add a new alias.
69+
70+
```php
71+
# Laravel 11
72+
use Suarez\UtmParameter\Middleware\UtmParameters;
73+
74+
->withMiddleware(function (Middleware $middleware) {
75+
$middleware
76+
->alias([
77+
/* ... keep the existing mappings here */
78+
'utm-parameters' => UtmParameters::class,
79+
])
80+
->web(append: [
81+
/* ... keep the existing mappings here */
82+
UtmParameters::class
83+
]);
84+
})
85+
```
86+
87+
To apply UTM-Parameters to specific routes, use the following middleware: `utm-parameters`
88+
89+
```php
90+
Route::middleware('utm-parameters')
91+
->get('langing-page/{slug}', 'LandingPageController@show');
92+
```
93+
94+
#### Laravel 10
95+
5196
Open the `app/Http/Kernel.php` file and add a new item to the `web` middleware group:
5297

5398
```php
99+
# Laravel 10 and below
54100
protected $middlewareGroups = [
55101
'web' => [
56102
/* ... keep the existing middleware here */
@@ -59,16 +105,10 @@ protected $middlewareGroups = [
59105
];
60106
```
61107

62-
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.
108+
To enable UTM-Parameters only for certain requests to your site, add a new mapping to the `middlewareAliases` Array.
63109

64110
```php
65-
# Laravel 9 and below
66-
protected $routeMiddleware = [
67-
/* ... keep the existing mappings here */
68-
'utm-parameters' => \Suarez\UtmParameter\Middleware\UtmParameters::class,
69-
];
70-
71-
# Laravel 10
111+
# Laravel 10 and below
72112
protected $middlewareAliases = [
73113
/* ... keep the existing mappings here */
74114
'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
101141
```
102142

103143
```php
104-
105144
// Some Task in your Class
106145
public function someTask()
107146
{

composer.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
}
1212
],
1313
"require": {
14-
"php": "^8.0|^8.1",
15-
"illuminate/support": "^8.0|^9.0|^10.0",
16-
"illuminate/contracts": "^8.0|^9.0|^10.0"
14+
"php": "^8.1|^8.2",
15+
"illuminate/support": "^10.0|^11.0",
16+
"illuminate/contracts": "^10.0|^11.0"
1717
},
1818
"require-dev": {
19-
"nunomaduro/collision": "^5.10|^6.0|^7.0",
20-
"orchestra/testbench": "^6.22|^7.0|^8.0",
19+
"nunomaduro/collision": "^7.0|^8.1",
20+
"orchestra/testbench": "^7.0|^8.0|^9.0",
2121
"phpunit/phpunit": "^9.5|^10.0",
2222
"friendsofphp/php-cs-fixer": "^3.0"
2323
},

phpunit.xml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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">
3-
<coverage>
4-
<include>
5-
<directory suffix=".php">./src</directory>
6-
</include>
7-
</coverage>
2+
<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">
83
<testsuites>
94
<testsuite name="Unit">
105
<directory suffix="Test.php">./tests</directory>
116
</testsuite>
127
</testsuites>
8+
<source>
9+
<include>
10+
<directory suffix=".php">./src</directory>
11+
</include>
12+
</source>
1313
</phpunit>

src/Middleware/UtmParameters.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Closure;
66
use Illuminate\Http\Request;
7-
use Illuminate\Http\Response;
87
use Suarez\UtmParameter\UtmParameter;
98

109
class UtmParameters
@@ -32,7 +31,7 @@ public function handle(Request $request, Closure $next)
3231
* @param \Illuminate\Http\Request $request
3332
* @param \Illuminate\Http\Response $response
3433
*
35-
* @return bool
34+
* @return \Illuminate\Http\Request
3635
*/
3736
protected function shouldAcceptUtmParameter(Request $request)
3837
{

src/UtmParameter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct($parameters = [])
2121
/**
2222
* Bootstrap UtmParameter.
2323
*
24-
* @param array|null $parameters
24+
* @param array|string|null $parameters
2525
*
2626
* @return UtmParameter
2727
*/

0 commit comments

Comments
 (0)