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