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