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