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