first(); } public function openFre() { return $this->returnResponse(Product::has('fractional_real_estate')->with('fractional_real_estate.companies')->open()->active()->latest()->get()); } public function fullyFundedFRE() { return $this->returnResponse(Product::has('fractional_real_estate')->with('fractional_real_estate.companies')->fullyFunded()->active()->latest()->get()); } public function resaleFRE() { return $this->returnResponse(Product::has('fractional_real_estate')->with('fractional_real_estate.companies')->resale()->active()->latest()->get()); } public function product($slug){ return $this->returnSingleData(FractionalRealEstate::where('slug',$slug)->first()); } public function returnSingleData($freProduct){ try { return (new FractionalRealEstateResource($freProduct)) ->response() ->setStatusCode(200); } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 400); } } public function returnResponse($product) { try { foreach ($product as $fre) { $fre->fractional_real_estate->property_img = $fre->fractional_real_estate->getRawOriginal('property_image'); } return (new Resource($product)) ->response() ->setStatusCode(200); } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 400); } } public function learnMore() { return $this->returnData(FAQ::where('tag_id', Tag::FractionalRealEstateId)->active()->where('faq_type', '0')->get()); } public function returnData($data) { return $data ? $this->apiResponse($data, 200) : $this->apiResponse($data, 400); } public function downloadFile($fileName){ if(\File::exists('public/uploads/product/presentation/'.$fileName)) { return response()->download(public_path('/uploads/product/presentation/'.$fileName)); } else if(\File::exists('public/uploads/product/fact_sheet/'.$fileName)) { return response()->download(public_path('/uploads/product/fact_sheet/'.$fileName)); } return "File Not Found"; } }