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