@rediska Try
@foreach($features as $feature)
{{ dd($feature['title']) }}
@endforeach
Please help me with a stupid question I am getting data like this:
$features = $products->pluck('features')
->unique()
->filter(function($value, $key) {
return $value != '[]';
});
Using foreach I iterate over the results:
@foreach($features as $feature)
{{dd($feature)}}
@endforeach
Illuminate\Database\Eloquent\Collection {#1784 ▼
#items: array:1 [▼
0 => App\Models\Feature {#1823 ▼
#fillable: array:9 [▶]
-//-
#attributes: array:12 [▼
"id" => 5
"title" => "buttons"
"created_at" => "2023-05-27 18:04:36"
"updated_at" => "2023-05-28 08:15:50"
"deleted_at" => null
]
-//-
So far everything is great. But until I display the title
@foreach($features as $feature)
{{dd($feature->title)}}
@endforeach
I am getting this kind of error. What am I doing wrong?
Exception Property [title] does not exist on this collection instance.
@Rediska sorry, it is a collection but your array is in that collection. So you are looping through the one item in the collection, then trying to call the property on that single collection, whereas you need to get the first() from your collection then loop through the items instead
Please or to participate in this conversation.