'Created Address', 'message' => 'You have successfully created a new Address' ]; } /** @var CanCreateAddress */ private $canCreateAddress; /** @var FetchesDistrict */ private $fetchesDistrict; /** @var FetchesCompany */ private $fetchesCompany; /** @var CreatesAddress */ private $createsAddress; /** @var CheckMilestonesForRewardProcessor */ private $checkMilestonesForRewardProcessor; /** * CreateAddressLogic constructor. * @param CanCreateAddress $canCreateAddress * @param FetchesDistrict $fetchesDistrict * @param FetchesCompany $fetchesCompany * @param CreatesAddress $createsAddress * @param CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor */ public function __construct(CanCreateAddress $canCreateAddress, FetchesDistrict $fetchesDistrict, FetchesCompany $fetchesCompany, CreatesAddress $createsAddress, CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor) { $this->canCreateAddress = $canCreateAddress; $this->fetchesDistrict = $fetchesDistrict; $this->fetchesCompany = $fetchesCompany; $this->createsAddress = $createsAddress; $this->checkMilestonesForRewardProcessor = $checkMilestonesForRewardProcessor; } /** * @param Request $request * @return JsonResponse * @throws \App\Classes\Exceptions\AccessForbiddenException * @throws \App\Classes\Exceptions\MalformedRequestException * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request) : JsonResponse { $district = $this->fetchesDistrict->execute(['id' => $request->input('district_id')]); $object = new AddressObject($request->input('street_one'), $request->input('street_two'), $district->country_id, $district->state_id, $district->id, $request->input('post_code')); $this->canCreateAddress->passes($object); $company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]); $query = $this->createsAddress->execute($company, $object); //cief todo: case study 6 // $user = $company->employees()->first(); // $this->checkMilestonesForRewardProcessor->execute($user, [Milestones::MILESTONE_6]); return $this->resourceResponse(new AddressResource($query)); } }