belongsTo(MarketplaceSellerForm::class,'seller_forms_id'); } public function buyer(){ return $this->belongsTo(MarketplaceBuyerForm::class,'seller_forms_id'); } public function company(){ return $this->belongsTo(Company::class,'fractional_real_estate_platform'); } public function Sluggable(): array { return [ 'slug' => [ "source" => 'property_name', 'onUpdate' => true ] ]; } public function getCategoryAttribute() { return 'Fractional Real Estate'; } public function getDiscountAttribute($id){ $values = MarketplaceFractionalRealEstateSeller::where('id', $this->id)->first(); // dd($values->expected_selling_price); // return (string)round(((int)$values->expected_selling_price - (int)$values->current_market_value_of_the_property)/(int)$values->current_market_value_of_the_property * 100,3); if($values->current_market_value_of_the_property <= 0) { return (string)0; } return (string)round((intval($values->expected_selling_price) - intval($values->current_market_value_of_the_property))/intval($values->current_market_value_of_the_property) * 100,3); } public function getBidAttribute($id){ $values = MarketplaceFractionalRealEstateSeller::where('id', $this->id)->first(); if($values->current_market_value_of_the_property <= 0) { return (string)0; } $bids = MarketplaceBuyerForm::where(['associated_id' => $this->id, 'table' => 'marketplace_fre_sellers'])->where('status','!=','Sold')->get(); $bidArr = []; foreach($bids as $bid){ $bidArr[] = round(($bid->getAttributes()['total_purchase_value'] - $this->current_market_value_of_the_property)/$this->current_market_value_of_the_property * 100,3); } if($bidArr){ $bid = (int)max($bidArr); return (string)$bid; } return (string)0; } public function getSoldStatusAttribute($id) { // return MarketplaceBuyerForm::where('associated_id', $id)->where('status', 'Sold')->exists() ? 'SOLD' : 'OPEN'; // dd($id); // $buyerData = MarketplaceBuyerForm::where('associated_id', $this->id)->where('status', 'Sold')->get(); // $totalSellUnits = 0; // $buyerData->each(function($data) use($totalSellUnits){ // return $totalSellUnits += (int)$data->no_of_units_you_wish_to_buy; // }); // $id = $this->id; if(MarketplaceBuyerForm::where(['associated_id'=>$id,'table' => 'marketplace_fre_sellers'])->exists()) { $getFREData = MarketplaceFractionalRealEstateSeller::where('id',$id)->first(); // $aifData = (int)$getFREData->no_of_units_you_wish_to_sell; // $remainUnits = $aifData - $totalSellUnits; if($getFREData->current_market_value_of_the_property <= 0) { return 'SOLD'; } else{ return 'OPEN'; } }else{ return 'OPEN'; } } }