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