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