decode_arr(request()->categories) ?? null; $assetType = request()->assetType ?? null; $firstTime = true; if($firstTime) { $assetType = 'financial-assets'; $firstTime = false; } $geographicFocus = request()->geographicFocus ?? null; $products = $this->filterData(request()->search ?? '', $urlCategories, $assetType, $geographicFocus); // dd($products->toArray()); $type = FractionalRealEstate::select('asset_type')->distinct()->get(); $categories = Product::query() ->join('categories', 'products.categories_id', 'categories.id') ->select('categories.id', 'category_name') ->distinct('categories_id') ->where('categories.status', true) ->get(); // $productsWithCategories = $this->filterData(request()->search ?? '', $urlCategories, $assetType, $geographicFocus); // dd($products); return view('Frontend.Pages.handpicked-investment', compact('products', 'type', 'categories', 'urlCategories')); } function fetchData(Request $request) { if ($request->ajax()) { $firstTime = $request->get('assetType') ?? 'financial-assets'; // dd($firstTime); $products = $this->filterData($request->get('query'), $request->get('categories'), $firstTime, $request->get('geographicFocus')); // $productsWithCategories = $this->filterData($request->get('query'), $request->get('categories'), $request->get('assetType'), $request->get('geographicFocus')); return view('Frontend.Pages.handpicked-investment.pagination', compact('products'))->render(); } } public function filterData($query, $categories, $assetType, $geographicFocus) { // dd($query, $categories, $assetType, $geographicFocus); if (!is_array($categories) && $categories) $categories = explode(',', $categories); $faCategoriesArr = [ // Category::DebtFundId, // Category::SovereignGovernmentBondId, // Category::GlobalMutualFundId, // Category::EquitiesId, Category::FractionalRealEstateId, Category::VentureCapitalFundId, Category::InfrastructureFundId, Category::AngelFundId, Category::PrivateEquityFundId, Category::FundForDistressedAssetId, Category::LongOnlyFundId, Category::PrivateCreditFundId, Category::PrivateRealEstateFundId, Category::HedgeFundId, Category::PrivateInvestmentInPublicEquityFundId, Category::GlobalHedgeFundId, Category::GlobalPrivateEquityFundId, Category::GlobalVentureCapitalFundId, Category::GlobalPrivateCreditFundId, ]; $reCategoriesArr = [ Category::IndianResidentialRealEstateID, Category::IndianCommercialRealEstateID, Category::IndianIndustrialRealEstateID, Category::GlobalResidentialRealEstateID, Category::GlobalCommercialRealEstateID, Category::GlobalIndustrialRealEstateID, ]; $products = Product::query() ->select(DB::raw('products.id, products.description, fre.property_image, products.categories_id as category_id, coalesce(fre.property_name_and_location,aif.fund_name,re.property_name,funds.fund_name) as product_name'), DB::raw('coalesce(companies.company_logo) as company_logo'), DB::raw('coalesce(fre.slug,aif.slug,re.slug, funds.slug) as slug'), DB::raw('coalesce(fre.geographic_focus,aif.geographic_focus,re.geographic_focus, funds.geographic_focus) as geographic_focus'), DB::raw('coalesce(aif.minimum_investment,fre.minimum_investment,funds.minimum_investment,re.total_price) as minimum_investment'), // DB::raw('coalesce(aif.description,fre.property_description,re.remarks,funds.fund_description) as description'), // DB::raw('coalesce(fre.property_description,products.description) as description'), // 'products.description', DB::raw('coalesce(categories.category_name) as category_name')) ->leftJoin('fractional_real_estates as fre', 'products.id', 'fre.products_id') ->leftJoin('alternative_investment_funds as aif', 'products.id', 'aif.products_id') // ->leftJoin('companies', 'fre.companies_id', 'companies.id') ->leftJoin('real_estates as re', 'products.id', 're.products_id') ->leftJoin('funds', 'products.id', 'funds.products_id') ->leftJoin('categories', 'products.categories_id', 'categories.id') ->leftJoin('companies',function($query){ $query->on('fre.companies_id', 'companies.id') ->orOn('aif.companies_id', 'companies.id') ->orOn('funds.platform_partner', 'companies.id') ->orOn('re.platform_partner', 'companies.id'); }) ->when($assetType == 'financial-assets', function ($query) use ($faCategoriesArr, $geographicFocus) { $query->whereIn('products.categories_id', $faCategoriesArr); $query->when($geographicFocus, function ($query) use ($geographicFocus) { $query->where(function ($query) use ($geographicFocus) { $query->where('fre.geographic_focus', $geographicFocus); $query->orWhere('aif.geographic_focus', $geographicFocus); $query->orWhere('funds.geographic_focus', $geographicFocus); }); }); }) ->when($assetType == 'real-assets', function ($query) use ($reCategoriesArr, $geographicFocus) { $query->whereIn('products.categories_id', $reCategoriesArr); $query->when($geographicFocus, function ($query) use ($geographicFocus) { $query->where('re.geographic_focus', $geographicFocus); }); }) ->when($assetType && $geographicFocus, function ($query) use ($geographicFocus) { $query->where(function ($query) use ($geographicFocus) { $query->where('fre.geographic_focus', $geographicFocus) ->orWhere('aif.geographic_focus', $geographicFocus) ->orWhere('funds.geographic_focus', $geographicFocus) ->orWhere('re.geographic_focus', $geographicFocus); }); }) ->when($categories, function ($query) use ($categories) { $query->whereIn('products.categories_id', $categories); }) ->where(function ($query) { $query->where('products.status', true); $query->where('categories.status', true); }) ->paginate(1000000); // ->get(); // dd($query, $categories); $products->appends(['search' => $query, 'categories' => $this->encode_arr($categories)]); return $products->withPath('/primary-investment'); } function encode_arr($data) { return base64_encode(serialize($data)); } function decode_arr($data) { return unserialize(base64_decode($data)); } }