Reputation: 442
I'm trying to loop through an object in an array in Laravel.
I made a foreach
to loop through my $request->newTags
what is an object and I just return the key. my goal is to access each tag_name
in my request object
what has an array
with the multiple indexes what contain the tag_name
.
foreach ($request->newTags as $tag) {
return $tag;
}
how can I access each tag_name?
Upvotes: 1
Views: 6407
Reputation: 1
@foreach ($dates as $key => $value)
@foreach ($humans as $human)
{{ $human[$key]['date'] }}
@endforeach
@endforeach
Upvotes: 0
Reputation: 611
You are using return on each iteration which will exit the function first ooff.But it doesnt matter because newTags only contains one item, which is an array. So it sounds like you have an object attribute $tags->newtags which is an array containing an array. I bet that this will not throw an error for example:
echo $tags[0]["tag_name"];
Your problem is nesting.
Upvotes: 1
Reputation: 195
Try this
foreach ($request->newTags as $tag) {
return $tag.tag_name;
}
Upvotes: 0