repository = $repository; $this->createsCompany = $createsCompany; $this->createsAddress = $createsAddress; } /** * @param Request $request * @return JsonResponse * @throws InternalServerErrorException */ public function execute(Request $request){ try { $object = new CompanyObject($request->input('marking'), $request->input('name'),$request->input('email'), $request->input('registration_no'), $request->input('tax_no')); $existing = $this->repository->where('marking', $object->getMarking())->get(); if ($existing->count() !== 0) { throw new ResourceConflictException("Marking already exists"); } $company = $this->createsCompany->execute($object); $address = new AddressBookObject(1, $company->id, $request->input('name'), $request->input('contact'), $request->input('street_one'), $request->input('street_two'), $request->input('city'), $request->input('state'), $request->input('post_code'), $request->input('country'), true, true); $this->createsAddress->execute($address); return new JsonResponse(null, HttpStatus::RESOURCE_CREATED); } catch (ResourceConflictException $exception){ throw new InternalServerErrorException("Failed to create importer because {$exception->getMessage()}"); } } }