A for loop for my attributes - Laravel

Hi !

I have objects with many attributes , for instance I have : Film1/Film2/…/Film300 each one with a corresponding title and I would like to show them all without writing each one in my blade.
So I had the idea of using a for loop like that :

@for ($i = 1; $i < 301; $i++)
@{{result.Film(i)}} -> but I don’t know how to call my variable i inside my result ? Do you have any idea ?

Thank you :slight_smile:

Anyone ? :cry:

Could you give me more details?
I don’t understand why you escape {{results.film}} and why are your data from.

If you get the data from the database, why not use a foreach loop instead?

Thanks for responding,

My object form is like that :


And in my blade I would like to show all the films but whithout writing {{result.Film1}} {{result.Film2}}…

Do you see?

I’m not really should, it looks like each film is a property, as if it’s a separate column in the database. Could you post your model here?

If it’s how you said, you could use the {!! !!} syntax and figure out a way to concatenate string to generate the variable name, like ${film$i} (something similar).

1 Like

I would like to generate the variable name like that :

@for ($i = 1; $i < 301; $i++)

This is working !!!