[], 'after' => ['create'], ]; /** * Handle the WorkorderActionEvent. * * @param WorkorderActionEvent $event * @return mixed */ public function handle(WorkorderActionEvent $event) { $function = Str::camel($event->action); return $this->$function($event); } /** * Create a new $workorder. * * @param WorkorderActionEvent $event * @return void */ public function create(WorkorderActionEvent $event) { $client = $event->workorder->client; Notification::send($client, new WorkorderActionNotification($event)); } /** * Handle the WorkorderActionEvent as a listener. * * @param WorkorderActionEvent $event * @return mixed */ public function asListener(WorkorderActionEvent $event) { if ($this->isAllowed($event)) { return $this->handle($event); } } /** * Check if the event action is allowed. * * @param WorkorderActionEvent $event * @return bool */ private function isAllowed(WorkorderActionEvent $event) { if ($event->when == 'before' && !in_array($event->action, $this->allowedActions['before'])) { return false; } if (($event->when == 'after' && !in_array($event->action, $this->allowedActions['after'])) ) { return false; } return true; } }