Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Increase variable in column name Laravel

I have those columns in my database table :

value_day_1 | value_day_2| value_day_3 |……|value_day_36

I’m trying to display each value in a view using a for loop

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@for ($n=1;$n<37;n++)
     {{ $day->value_day_? }}
@endfor

How can i replace the ? by $n ?

>Solution :

One solution would be

@foreach(range(1,37) as $n)
    @php($column = 'value_day_' . $n;)
    {{ $day->$column }}
@endforeach

I prefer to use range instead of the for syntax but it is not neccessary for your problem

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading