Skip to content

Commit

Permalink
- update
Browse files Browse the repository at this point in the history
  • Loading branch information
toni-suarez committed Mar 13, 2024
1 parent 3a94568 commit 8cfd8df
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 16 deletions.
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
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>
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 8cfd8df

Please sign in to comment.