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