Skip to content
Advertisement

User variables of a function, in another function

I have a Laravel app, which the following PHP code:

JavaScript

Im trying to echo the the title along with the tags, right after the commented place, but it fails to provide the correct output. I was wondering if Im using the correct way or my workaround is completely wrong.

Im using this code in the commented part:

JavaScript

After doing some tests, I realized that if I use

JavaScript

right after

JavaScript

at my createTags function, it seems that all tags are output correctly.

Im wondering if I can store all $tags inside the createTag function’s foreach, under a globally accessed variable that would be used in the initial handle function echoed.

Advertisement

Answer

Guessing the post item model has a relation “tags” you could try this:

JavaScript

Also if you would just like to echo the tags on the commented place, try this:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement