Bow Framework's event driver system is very simple event subscription and interpage page event:
Let's show a little exemple:
use Bow\Event\Event;
// Add listener on send.mail event
Event::on("email.sent", function (array $payload) {
$name = $payload["name"];
echo "An email was sent to $name";
});
// Emit the send.mail event
Event::emit("email.sent", ["name" => "Franck DAKIA"]);
// With helper
event("email.sent", ["name" => "Franck DAKIA"])NB: Is recommanded to write all event listener into simple class and define the event to the app Kernel file in boot method.
use App\Models\Activity;
use Bow\Event\EventListener;
class ActivityEvent extends EventListener
{
/**
* Listener method
*
* @param array payload
* @return mixed
*/
public function process($payload)
{
Activity::create($payload);
// $payload => ['action' => 'update profile']
}
}Into Kernel file
public function events()
{
return [
"user.activity" => [
ActivityEvent::class
]
]
}Send the event now
event('user.activity', ['action' => 'update profile']);