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