[], 'after' => ['create'], ]; /** * Handle the EnquiryActionEvent. * * @param EnquiryActionEvent $event * @return mixed */ public function handle(EnquiryActionEvent $event) { $function = Str::camel($event->action); return $this->$function($event); } /** * Create a new $enquiry. * * @param EnquiryActionEvent $event * @return void */ public function create(EnquiryActionEvent $event) { $client = $event->enquiry->client; Notification::send($client, new EnquiryActionNotification($event)); } /** * Handle the EnquiryActionEvent as a listener. * * @param EnquiryActionEvent $event * @return mixed */ public function asListener(EnquiryActionEvent $event) { if ($this->isAllowed($event)) { return $this->handle($event); } } /** * Check if the event action is allowed. * * @param EnquiryActionEvent $event * @return bool */ private function isAllowed(EnquiryActionEvent $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; } }