Files
freeu-project/app/Http/Controllers/Frontend/FractionalRealEstateController.php

100 lines
4.4 KiB
PHP
Raw Normal View History

2024-03-28 14:52:40 +05:30
<?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;
2024-04-29 14:42:22 +05:30
use App\Models\ProductImage;
2024-03-28 14:52:40 +05:30
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();
2024-03-28 14:52:40 +05:30
$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'));
2024-03-28 14:52:40 +05:30
}
public function product($slug)
{
$fractionalRealEstate = $this->fractionalRealEstateData($slug)->getData()->data;
2024-06-12 13:03:22 +05:30
// dd($fractionalRealEstate->products_id);
// $otherFRE = FractionalRealEstate::query()
// ->join('products', 'fractional_real_estates.products_id', 'products.id')
// ->where(['status' => true, 'categories_id' => 2])
// ->where('slug', '!=', $slug)
// ->get();
// $productData = FractionalRealEstate::where('slug', '=', $slug)->first();
// dd($productData->toArray(),$fractionalRealEstate);
$productData = Product::with('product_images')->where('id', $fractionalRealEstate->products_id)->first();
2024-06-13 14:44:32 +05:30
2024-06-12 13:03:22 +05:30
return view('Frontend.Pages.fractional-real-estate.product', compact('fractionalRealEstate', 'productData'));
2024-03-28 14:52:40 +05:30
}
public function downloadFilePersantation($filename)
{
2024-03-28 14:52:40 +05:30
// dd($filename);
if (\File::exists('public/uploads/product/presentation/' . $filename)) {
2024-03-28 14:52:40 +05:30
// 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 {
2024-03-28 14:52:40 +05:30
return "file not found";
}
2024-04-16 15:17:56 +05:30
// dd('hello');
2024-03-28 14:52:40 +05:30
}
public function fractData($type = 'Open')
2024-03-28 14:52:40 +05:30
{
try {
2024-06-04 16:10:48 +05:30
$product = Product::has('fractional_real_estate')->with('fractional_real_estate.companies','product_images')->where('type',$type)->active()->get();
foreach ($product as $fre) {
2024-03-28 14:52:40 +05:30
$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);
}
2024-04-12 15:07:34 +05:30
}
2024-03-28 14:52:40 +05:30
public function fractionalRealEstateData($slug)
{
2024-03-28 14:52:40 +05:30
try {
return (new FractionalRealEstateResource(FractionalRealEstate::where('slug', $slug)->first()))
2024-03-28 14:52:40 +05:30
->response()
->setStatusCode(200);
} catch (\Exception $e) {
return response()->json(['message' => $e->getMessage()], 400);
}
}
2024-04-29 14:42:22 +05:30
public function delete_fractional_image(Request $request){
$image = ProductImage::find($request->image_id);
$previous_image = public_path($image->images);
// \File::delete($previous_image);
if (!empty($previous_image)) {
$previousImagePath = $previous_image;
if (file_exists($previousImagePath)) {
unlink($previousImagePath);
}
}
$image->id = $request->image_id;
$image->delete();
return response()->json(['success' => true, 'status' => 200]);
// dd("requ",$request->all());
}
2024-03-28 14:52:40 +05:30
}