PHP code example of eventsauce / laravel-eventsauce
1. Go to this page and download the library: Download eventsauce/laravel-eventsauce library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use App\Domain\SendConfirmationNotification;
use EventSauce\LaravelEventSauce\AggregateRootRepository;
final class RegistrationAggregateRootRepository extends AggregateRootRepository
{
protected array $consumers = [
SendConfirmationNotification::class,
];
protected string $queue = 'registrations';
}
use App\Events\UserWasRegistered;
use App\Models\User;
use App\Notifications\NewUserNotification;
use EventSauce\LaravelEventSauce\Consumer;
final class SendConfirmationNotification extends Consumer
{
protected function handleUserWasRegistered(UserWasRegistered $event): void
{
User::where('email', $event->email())
->first()
->notify(new NewUserNotification());
}
}
use App\Domain\SendConfirmationNotification;
use EventSauce\LaravelEventSauce\AggregateRootRepository;
final class RegistrationAggregateRootRepository extends AggregateRootRepository
{
protected array $consumers = [
SendConfirmationNotification::class,
];
}
use EventSauce\LaravelEventSauce\Consumer;
use Illuminate\Contracts\Queue\ShouldQueue;
final class SendConfirmationNotification extends Consumer implements ShouldQueue
{
...
}