Standard Events
Events emitted by VelvetCMS Core with their payloads.
VelvetCMS Core emits events at key lifecycle points. Hook into these to extend functionality without modifying core code.
Application Events #
app.booting #
Fired before service providers are booted.
$events->listen('app.booting', function () {
// Early initialization
});
Payload: none
app.booted #
Fired after all service providers have booted. The application is fully initialized.
$events->listen('app.booted', function () {
// App is ready
});
Payload: none
Router Events #
router.matching #
Fired when the router starts matching a request.
$events->listen('router.matching', function (array $data) {
// $data['method'] - HTTP method (GET, POST, etc.)
// $data['path'] - Request path
// $data['original_method'] - Original method before spoofing
});
router.matched #
Fired when a route matches successfully.
$events->listen('router.matched', function (array $data) {
// $data['route'] - Route definition array
// $data['params'] - Extracted route parameters
});
Page Events #
page.loading #
Fired before a page is loaded from storage.
$events->listen('page.loading', function (string $slug) {
// $slug - Page slug being loaded
});
page.loaded #
Fired after a page is loaded.
$events->listen('page.loaded', function (array $page) {
// $page - Full page data array
});
page.saved #
Fired after a page is saved.
$events->listen('page.saved', function (array $page) {
// $page - Saved page data
// Good for cache invalidation, search indexing
});
page.deleted #
Fired after a page is deleted.
$events->listen('page.deleted', function (string $slug) {
// $slug - Deleted page's slug
});
Exception Events #
exception.reporting #
Fired when an exception is being reported (logged).
$events->listen('exception.reporting', function (array $data) {
// $data['exception'] - The Throwable
// $data['request'] - Current Request object
});
exception.rendering #
Fired when an exception is being rendered to a response.
$events->listen('exception.rendering', function (array $data) {
// $data['exception'] - The Throwable
// $data['request'] - Current Request object
});
CLI Events #
commands.registering #
Fired while the CLI registry is being populated. The listener receives VelvetCMS\Commands\CommandRegistry.
use VelvetCMS\Commands\CommandRegistry;
$events->listen('commands.registering', function (CommandRegistry $registry): void {
$registry->register('ping', PingCommand::class);
});
Queue job lifecycle events #
Emitted by VelvetCMS\Queue\Worker during queue:work:
| Event | Payload |
|---|---|
queue.job.processing |
VelvetCMS\Queue\Job |
queue.job.processed |
Same job after success |
queue.job.released |
Same job when re-queued after a retryable failure |
queue.job.failed |
['job' => Job, 'exception' => \Throwable] |
Database Events #
migrations.registering #
Fired when migrations are being discovered.
$events->listen('migrations.registering', function (\VelvetCMS\Core\Application $app) {
// Register paths or programmatic migrations
});
Payload: the bootstrapped Application instance (velvet entrypoint dispatches accordingly).
Module Events #
modules.registering #
Fired before modules are registered.
$events->listen('modules.registering', function () {
// Modify module discovery
});
modules.registered #
Fired after all modules are registered.
$events->listen('modules.registered', function () {
// All modules available
});
Example: Complete Event Integration #
class AnalyticsServiceProvider extends ServiceProvider
{
public function boot(): void
{
$events = $this->app->make('events');
// Track page views
$events->listen('page.loaded', function (array $page) {
$this->trackPageView($page['slug']);
});
// Log route matches for debugging
$events->listen('router.matched', function (array $data) {
if (config('app.debug')) {
app('logger')->debug('Route matched', $data);
}
});
// Send error notifications
$events->listen('exception.reporting', function (array $data) {
if ($this->shouldNotify($data['exception'])) {
$this->notifyTeam($data['exception']);
}
});
}
}