Yosef
Yosef

Reputation: 442

Loop through object within an array Laravel

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;
 }

and i get my response enter image description here

how can I access each tag_name?

Upvotes: 1

Views: 6407

Answers (3)

Ibnnu Works
Ibnnu Works

Reputation: 1

@foreach ($dates as $key => $value)
    @foreach ($humans as $human)
        {{ $human[$key]['date'] }}
    @endforeach
@endforeach

Upvotes: 0

OneLiner
OneLiner

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

Songtham T.
Songtham T.

Reputation: 195

Try this

foreach ($request->newTags as $tag) {
   return $tag.tag_name;
 }

Upvotes: 0

Related Questions