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