How to print data?

0 like 0 dislike
14 views
@foreach ($post->tags as $tag) {{$tag}}@endforeach


Which brings

[{"id":17,"title":"23525246","created_at":null,"updated_at":null}][{"id":18,"title":"674","created_at":null,"updated_at":null}][{"id":19,"title":"dssdfsdf ","created_at":null,"updated_at":null}][{"id":20,"title":"er","created_at":null,"updated_at":null}]


When you use {{$tag->id}} gives an error

Property [id] does not exist on this collection instance. (View: D:\\OpenServer\\domains\\laravel\esources\\views\\posts\\show.blade.php)
by | 14 views

1 Answer

0 like 0 dislike
Because you have a $tag array of objects.
Do
{{ $tag[0]->id }}
or
{{ $tag->first()->id }}
by

Related questions

0 like 0 dislike
4 answers
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked Jun 14, 2019 by Ka4_Piton
0 like 0 dislike
1 answer
asked Jun 3, 2019 by codeturn
0 like 0 dislike
1 answer
asked Jun 8, 2019 by adam_carraway
110,608 questions
257,186 answers
0 comments
33,932 users