[], 'after' => ['publish', 'submit', 'approve'], ]; public function handle(AdWorkflowEvent $event) { $function = Str::camel($event->transition); return $this->$function($event); } /** * Sends a notification to the client when the $ad is submitted. * * @param AdWorkflowEvent $event The event object. * @return void */ public function submit(AdWorkflowEvent $event) { $client = $event->ad->client; Notification::send($client, new AdWorkflowNotification($event)); } /** * Sends a notification to the client when the $ad is published. * * @param AdWorkflowEvent $event The event object. * @return void */ public function publish(AdWorkflowEvent $event) { $client = $event->ad->client; Notification::send($client, new AdWorkflowNotification($event)); } /** * Sends a notification to the client when the $ad is approved. * * @param AdWorkflowEvent $event The event object. * @return void */ public function approve(AdWorkflowEvent $event) { $client = $event->ad->client; Notification::send($client, new AdWorkflowNotification($event)); } /** * Handles the $ad workflow event as a listener. * * @param AdWorkflowEvent $event The event object. * @return void */ public function asListener(AdWorkflowEvent $event) { if (($event->when == 'before' && in_array($event->transition, $this->allowedTransitions['before']) || $event->when == 'after' && in_array($event->transition, $this->allowedTransitions['after'])) ) { return $this->handle($event); } } }