Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,18 @@ This package also supports the User-ID feature.
To start using the User-ID feature you've to add the ``TagManagerUserIdMiddleware`` in your 'web' middleware group directly after the ``TagManagerMiddleware``.

```php
// app/Http/Kernel.php

protected $middlewareGroups = [
'web' => [
...
\Label84\TagManager\Http\Middleware\TagManagerMiddleware::class,
\Label84\TagManager\Http\Middleware\TagManagerUserIdMiddleware::class,
...
// bootstrap/app.php

return Application::configure(basePath: dirname(__DIR__))
->withRouting(
//
)
->withMiddleware(function (Middleware $middleware): void {
$middleware->web(append: [
\Label84\TagManager\Http\Middleware\TagManagerMiddleware::class,
\Label84\TagManager\Http\Middleware\TagManagerUserIdMiddleware::class,
]);
})
```

By default the 'id' of the User model will be used. You change the key in ``config/tagmanager.php``.
Expand Down
15 changes: 9 additions & 6 deletions src/Http/Middleware/TagManagerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@ public function __construct(TagManager $tagManager, Session $session)
$this->session = $session;
}

/** @return mixed */
public function handle(Request $request, Closure $next)
public function handle(Request $request, Closure $next): mixed
{
if ($this->session->has(config('tagmanager.session_name'))) {
$this->tagManager->set($this->session->get(config('tagmanager.session_name')));
$sessionName = config('tagmanager.session_name');

$this->session->pull(config('tagmanager.session_name'));
if ($this->session->has($sessionName)) {
$this->tagManager->set(
collect((array) $this->session->get($sessionName, []))
);

$this->session->pull($sessionName);
}

$response = $next($request);

$this->session->flash(config('tagmanager.session_name'), $this->tagManager->get());
$this->session->flash($sessionName, $this->tagManager->get());

return $response;
}
Expand Down
Loading