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

87 lines
3.9 KiB
PHP

<?php
namespace App\Http\Controllers\Frontend;
use App\Http\Controllers\Controller;
use App\Models\FractionalRealEstate;
use App\Models\Product;
use Illuminate\Http\Request;
use App\Http\Resources\FractionalRealEstate as test;
use App\Http\Resources\FractionalRealEstateResource;
use App\Http\Controllers\Admin\ManageFreeUInvestments\FractionalRealEstateController as FractionalRealEstateFontendController;
class FractionalRealEstateController extends Controller
{
public function index()
{
$fractionalRealEstate = $this->fractData()->getData();
$openFRE = Product::has('fractional_real_estate')->with('fractional_real_estate.companies','categorys')->open()->active()->latest()->get();
$resaleFRE = Product::has('fractional_real_estate')->with('fractional_real_estate.companies','categorys')->resale()->active()->latest()->get();
$fullyFundedFRE = Product::has('fractional_real_estate')->with('fractional_real_estate.companies','categorys')->fullyFunded()->active()->latest()->get();
$learnMore = (new FractionalRealEstateFontendController)->fractionalRealEstateQuestionAndAnswer()->getData();
// $faqs = (new FractionalRealEstateFontendController)->fractionalRealEstateQuestionAndAnswerFaqs()->getData();
// dd($openFRE);
return view('Frontend.Pages.fractional-real-estate.index', compact('fractionalRealEstate','learnMore','openFRE', 'resaleFRE', 'fullyFundedFRE'));
}
public function product($slug)
{
$fractionalRealEstate = $this->fractionalRealEstateData($slug)->getData()->data;
$otherFRE = FractionalRealEstate::query()
->join('products', 'fractional_real_estates.products_id', 'products.id')
->where(['status' => true, 'categories_id' => 2])
->where('slug', '!=', $slug)
->get();
// dd($fractionalRealEstate);
$productData = FractionalRealEstate::where('slug','=',$slug)->first();
$productData = Product::where('id','=',$productData->products_id)->first();
// $productData['presentation_file'] = $productData->getRawOriginal('presentation');
// $productData['fact_sheet_file'] = $productData->getRawOriginal('fact_sheet');
// dd($fractionalRealEstate);
return view('Frontend.Pages.fractional-real-estate.product', compact('fractionalRealEstate','otherFRE','productData'));
}
public function downloadFilePersantation($filename){
// dd($filename);
if(\File::exists('public/uploads/product/presentation/'.$filename))
{
// dd('hello');
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));
}else{
return "file not found";
}
dd('hello');
}
public function fractData()
{
try {
$product = Product::has('fractional_real_estate')->with('fractional_real_estate.companies')->active()->get();
foreach($product as $fre)
{
$fre->fractional_real_estate->property_img = $fre->fractional_real_estate->getRawOriginal('property_image');
}
return (new test($product))
->response()
->setStatusCode(200);
} catch (\Exception $e) {
return response()->json(['message' => $e->getMessage()], 400);
}
}
public function fractionalRealEstateData($slug){
try {
return (new FractionalRealEstateResource(FractionalRealEstate::where('slug',$slug)->first()))
->response()
->setStatusCode(200);
} catch (\Exception $e) {
return response()->json(['message' => $e->getMessage()], 400);
}
}
}