Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdullahsari committed Feb 21, 2024
1 parent cd46423 commit d7e3a03
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ _* feature complete_
- [Automatic translation of messages](#automatic-translation-of-messages)
- [Accessibility](#accessibility)
- [Unit testing](#unit-testing)
- [Extending behavior](#extending-behavior)
- [View customization](#view-customization)
- [Testing](#testing)
- [Changelog](#changelog)
Expand Down Expand Up @@ -400,6 +401,43 @@ final class RegisterUserControllerTest extends TestCase
}
```

### Extending behavior

Imagine that you'd like to keep track of how many toasts are dispatched daily to display on an admin dashboard.
First, create a new class that encapsulates this logic:

```php
final readonly class DailyCountingCollector implements Collector
{
public function __construct(private Collector $next) {}

public function collect(Toast $toast): void
{
// increment the counter on durable storage

$this->next->collect($toast);
}

public function release(): array
{
return $this->next->release();
}
}
```

After that, extend the behavior in your `AppServiceProvider`:

```php
public function register(): void
{
$this->app->extend(Collector::class,
static fn (Collector $next) => new DailyCountingCollector($next)
);
}
```

That's it!

## View customization

> **Warning** You **must** keep the `x-data` and `x-init` directives and you **must** keep using the `x-for` loop.
Expand Down

0 comments on commit d7e3a03

Please sign in to comment.