2024-03-28 14:52:40 +05:30
< ? php
namespace App\Http\Controllers\Frontend ;
use App\Models\Product ;
use App\Models\Category ;
use Illuminate\Http\Request ;
use Illuminate\Support\Facades\DB ;
use App\Http\Controllers\Controller ;
use App\Models\FractionalRealEstate ;
class HandpickedInvestmentController extends Controller
{
public function index ()
{
2024-04-04 19:39:40 +05:30
2024-03-28 14:52:40 +05:30
$urlCategories = $this -> decode_arr ( request () -> categories ) ? ? null ;
$assetType = request () -> assetType ? ? null ;
$geographicFocus = request () -> geographicFocus ? ? null ;
$products = $this -> filterData ( request () -> search ? ? '' , $urlCategories , $assetType , $geographicFocus );
$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 ();
2024-04-02 13:10:02 +05:30
// $productsWithCategories = $this->filterData(request()->search ?? '', $urlCategories, $assetType, $geographicFocus);
2024-03-28 14:52:40 +05:30
// dd($products);
return view ( 'Frontend.Pages.handpicked-investment' , compact ( 'products' , 'type' , 'categories' , 'urlCategories' ));
}
function fetchData ( Request $request )
{
2024-04-04 19:39:40 +05:30
2024-03-28 14:52:40 +05:30
if ( $request -> ajax ()) {
$products = $this -> filterData ( $request -> get ( 'query' ), $request -> get ( 'categories' ), $request -> get ( 'assetType' ), $request -> get ( 'geographicFocus' ));
2024-04-04 19:39:40 +05:30
2024-04-02 13:10:02 +05:30
// $productsWithCategories = $this->filterData($request->get('query'), $request->get('categories'), $request->get('assetType'), $request->get('geographicFocus'));
2024-03-28 14:52:40 +05:30
return view ( 'Frontend.Pages.handpicked-investment.pagination' , compact ( 'products' )) -> render ();
}
}
public function filterData ( $query , $categories , $assetType , $geographicFocus )
{
2024-04-04 19:39:40 +05:30
// dd($query, $categories, $assetType, $geographicFocus);
2024-03-28 14:52:40 +05:30
if ( ! is_array ( $categories ) && $categories )
$categories = explode ( ',' , $categories );
$faCategoriesArr = [
Category :: FractionalRealEstateId ,
Category :: VentureCapitalFundId ,
Category :: InfrastructureFundId ,
Category :: AngelFundId ,
Category :: PrivateEquityFundId ,
Category :: DebtFundId ,
Category :: PrivateRealEstateFundId ,
Category :: HedgeFundId ,
Category :: PrivateInvestmentInPublicEquityFundId ,
Category :: SovereignGovernmentBondId ,
Category :: GlobalMutualFundId ,
Category :: EquitiesId ,
Category :: GlobalHedgeFundId ,
];
$reCategoriesArr = [
Category :: IndianResidentialRealEstateID ,
Category :: IndianCommercialRealEstateID ,
Category :: IndianIndustrialRealEstateID ,
Category :: GlobalResidentialRealEstateID ,
Category :: GlobalCommercialRealEstateID ,
Category :: GlobalIndustrialRealEstateID ,
];
$products = Product :: query ()
-> select ( DB :: raw ( 'products.id, 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_capital_commitment,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(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 ( 'categories' , 'products.categories_id' , 'categories.id' )
-> leftJoin ( 'funds' , 'products.id' , 'funds.products_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 == null && $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 );
})
2024-04-02 13:10:02 +05:30
-> where ( function ( $query ) {
2024-03-28 14:52:40 +05:30
$query -> where ( 'products.status' , true );
$query -> where ( 'categories.status' , true );
})
-> paginate ( 6 );
2024-04-04 19:39:40 +05:30
// dd($query, $categories);
2024-03-28 14:52:40 +05:30
$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 ));
}
}