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