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