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