-
app/Providers/EventServiceProvider.php
Open in GitHubuse App\Models\Extension; use Illuminate\Support\Facades\Event; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; class EventServiceProvider extends ServiceProvider { // ... public function boot() { // ... try { foreach (Extension::where('enabled', true)->get() as $extension) { $module = $extension->namespace . 'Listeners'; if (!class_exists($module)) { continue; } Event::subscribe(new $module); } } catch (\Exception $e) { // If the database is not yet migrated, this will throw an exception. } } // ... public function discoverEventsWithin(): array { return [ $this->app->path('Listeners'), ]; } }
-
app/Extensions/Events/DiscordWebhook/DiscordWebhookListeners.php
Open in GitHubuse App\Events\Invoice\InvoiceCreated; use App\Events\Invoice\InvoicePaid; use App\Events\Ticket\TicketCreated; use App\Events\Ticket\TicketMessageCreated; use App\Events\User\UserCreated; use App\Helpers\ExtensionHelper; class DiscordWebhookListeners { private function sendWebhook(string $title, string $message, array $fields = [], string $color = '00ff00'): void { // ... } public function handleInvoiceCreated(InvoiceCreated $event): void { // ... } public function handleInvoicePaid(InvoicePaid $event): void { // ... } public function newTicketMessage($event) { // ... } public function newUser($event) { // ... } public function newTicket($event) { // ... } // ... public function subscribe(): array { return [ InvoiceCreated::class => 'handleInvoiceCreated', InvoicePaid::class => 'handleInvoicePaid', TicketMessageCreated::class => 'newTicketMessage', UserCreated::class => 'newUser', TicketCreated::class => 'newTicket', ]; } }