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