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