Reputation: 1073
I have the following loop in template:
@foreach ($hotel->first()->images as $key => $image)
// Here I try to get $image->id
@endforeach
So, if display object:
{{$hotel->first()->images}}
It shows:
{"id":1,"filename":"5c52f95a48809728c7b4f2af2825cfb8.jpg","size":58349,"extention":"jpg","created_at":null,"path":"uploads","idElement":9}
When I try to get access to $image->id
insise loop I get error.
Upvotes: 0
Views: 75
Reputation: 479
If you are using Has One, you just need to get your variable, you dont need to use foreach.
echo $hotel->first()->images->filename;
Upvotes: 4