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