repository = $repository; } /** * @param OrderObject $order * @return Order * @throws CannotCreateOrderException */ public function execute(OrderObject $order): ?Order { try { $address = AddressBook::where('company_id', $order->getCompanyId()) ->where('default', true)->firstOrFail(); $this->repository->company_id = $order->getCompanyId(); $this->repository->marking = $order->getOrderId(); $this->repository->address_id = $address->id; $this->repository->current_step = Constants::ORDER_PROCESSING_STEP; $this->repository->save(); return $this->repository; } catch (\Exception $exception){ throw new CannotCreateOrderException($exception->getMessage()); } } }