PHP code example of chocofamilyme / laravel-pubsub
1. Go to this page and download the library: Download chocofamilyme/laravel-pubsub 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/ */
return [
/*
|--------------------------------------------------------------------------
| Listen for events
|--------------------------------------------------------------------------
|
| Define event name and it's listeners. Please notice that one event name may have multiple listeners
|
| Example:
|
| listen => [
| 'UserNotified' => [
| 'durable' => true,
| 'listeners' => [
| NotifyAboutDeviceChangeListener::class,
| ],
| ]
| ],
|
*/
'listen' => [
],
/**
* Define database tables for storing data (publishing events, incoming events, etc.)
*/
'tables' => [
'events' => 'pubsub_events'
]
];
artisan make:event
event(new UserUpdatedEvent(1, 'Josh'));
namespace App\Events;
use Chocofamilyme\LaravelPubSub\Events\PublishEvent;
class UserUpdatedEvent extends PublishEvent
{
public int $id;
public string $name;
public const EXCHANGE_NAME = 'exchangeName';
public const ROUTING_KEY = 'user.updated';
/**
* Create a new event instance.
*
* @param int $id
* @param string $name
*/
public function __construct(int $id, string $name)
{
$this->id = $id;
$this->name = $name;
}
}