Files
freeu-project/app/Services/Frontend/FractionalRealEstateService.php
Ritikesh yadav c661166e1d first commit
2024-03-28 14:52:40 +05:30

86 lines
2.7 KiB
PHP

<?php
namespace App\Services\Frontend;
use App\Models\Product;
use App\Models\Admin\FAQ;
use App\Models\Admin\Tag;
use App\Traits\HttpResponse;
use App\Models\FractionalRealEstate;
use App\Http\Resources\FractionalRealEstateResource;
use App\Http\Resources\FractionalRealEstate as Resource;
class FractionalRealEstateService
{
use HttpResponse;
public function getProductData($productsId){
return Product::where('id',$productsId)->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";
}
}