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