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