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