I know this is relatively simple but its driving me absolutely insane!
a little background, my app takes an xml feed to parse, this has nested fields suchs as features
its in my db, as an obj/array, with 'feature' as the key.
now my for each loop is displaying all this data in one UL.
Code Below.
Any Help Greatly Appreciated
//model
public static function getFeatures($id){
$featuresArray = [];
$featuresquery = DB::table('properties')
->selectRaw("features")
->where('id', $id)
->get('');
$k = $featuresquery;
foreach ($k as $feat):
if (is_array($feat)) {
$featuresArray[] = (array_key_exists('features', $feat)) ? $feat['features'] : '';
}
return $feat;
endforeach;
return $featuresArray;
}
//Controller
public function details($id) {
$property = Property::findorFail($id);
$agent = Agent::where("id",$property->agent_id)
->with([
'ads'
])->first();
$template = Agent::getTemplateName($agent);
$banners = Banner::getBanners($agent->id);
$areaAndLocations = Property::getAreaAndLocations($agent->id);
$property_type = Property::getPropertyTypes($agent->id);
$query_params = Property::getQueryParams();
$features = Property::getFeatures($property->id);
return view('frontend.'.$template.'.property.details', ['template' => $template, 'banners' => $banners, 'areaAndLocations' => $areaAndLocations, 'property_type' => $property_type, 'query_params' => $query_params, 'features' => $features])
->withDetails($property)
->withAgent($agent);
}
//View
<div class="features">
@foreach($features as $feature)
<ul><li>
{!! json_encode(json_decode($feature)) !!}
</li></ul>
@endforeach
</div>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire