1. Go to this page and download the library: Download rabbitevents/listener 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/ */
class SendNotification
{
public function handle($eventPayload)
{
Mailer::to(Arr::get($eventPayload, 'user.email'))
->subject('Payment Succeeded')
->message('...');
}
}
class AllItemEventsListener
{
public function handle($event, $payload)
{
match($event) => [
'item.created' => ...,
'item.deleted' => ...,
'item.updated' => ...,
];
}
}
/**
* Handle payment but only if the type is 'mytype'
*
* @param array $payload
* @return void
*/
public function handle($payload)
{
if (\Arr::get($payload, 'entity.type') !== 'mytype') {
return;
}
Entity::find(\Arr::get($payload, 'entity.id'))->activate();
}
namespace App\Listeners\RabbitEvents\Middleware;
class FilterEntities
{
/**
* @param string $event the event name. Passing only for wildcard events
* @param array $payload
*/
public function handle([$event,] $payload)
{
return !\Arr::get($payload, 'entity.type') == 'mytype';
}
}
use App\Listeners\RabbitEvents\Middleware\FilterEntities;
class PaymentListener
{
public array $middleware = [
FilterEntities::class,
`App\Listeners\RabbitEvents\Middleware\AnotherMiddleware@someAction`,
];
/**
* @param string $event the Event Name. Passing only for wildcard events
* @param array $payload
*/
public function middleware([$event, ]$payload)
{
return !\Arr::get($payload, 'entity.type') == 'mytype';
}
}
bash
php artisan rabbitevents:install
bash
php artisan rabbitevents:listen
bash
php artisan rabbitevents:list
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.