Afrikaans
Akan
Albanian
Amharic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Loops can be used to iterate over arrays are like objects in blade.
It's important to know loops in blade templates work the same as loops in PHP.
We will begin with that for each type of loop, as I think it would be the one you will most often use.
To work with realistic example, we will make use of their posts as a variable.
Our goal is to prepare a new page that will list old blog posts, titles.
First off, we need to move posts as variable out of this function.
We want to create a new route for displaying the lists of posts.
For this roots controller functions to have access to the post variable, now we add the use statements
after the function, the header inside the statement, you should list all variables that are not declared
inside the anonymous function.
So in our example, this is posts.
If you want or need to know more about anonymous functions in Puchi, go visit PPY documentation, page
the link you see on the screen on the resources.
Let's create a new route using the static jet method that you or I, we want our new page under is supposed
there are no arguments to disrupt.
It should render the Post's index template we are yet to create and the data pass to it is the Post's
right now.
To use this Post's variable, we actually have to add a used statement after the function header, the
same as we did previously.
At this point, I should mention that disarray can be generated using a shortcut in BHP.
Let me just paste it for you.
So if you called a BHP built in compact function, then it will produce an array where there will be
a key with the name exactly the same as the variable name and the value of the variable will be assigned
to that key.
So whenever you would like to be explicit and define the array or use the compact function is completely
up to you.
I prefer to be verbose, so I will stick to defining the full array.
You can read more about the compact function in the link.
Now, let's create the new template, The Post's index blade.
So essentially, this means creating an index blade profile file inside the posts folder to speed things
up.
We'll copy over the other template contents.
And just remove everything, what is inside the section content?
Now they're for each sentence is quite intuitive, first goes the array to iterate over, then they're
ASCII word and Furt is the variable name of the current element in the loop, the loop itself and swift
and for each directive.
Between the loop directives, we can now render the content of the current iteration variable, in our
case, it's an individual post.
So let's add a development and using their master syntax, let's output the post title now before we
go test it, we have to fix to the actual page title as we can't use the supposed variable outside the
scope of a loop.
It doesn't exist in here and this would cause an error.
So let's change it to just normal static text like blog posts and now save the changes and let's verify
it in the browser.
So the new URL should be just posts.
There it is.
We have the titles of our two blog posts.
As I've mentioned before, therefore, each directive works exactly the same as the for each loop.
So this means if you would also like to get the key of every element you iterate over and if we would
like to remind ourselves this array actually has keys explicitly specified, you can do that like you
would in which is you will specify another variable for the key and use the arrow.
Then we can output the key using mustache as well.
And maybe let's add a dot after it now, say the changes and let's see what this would output.
So there it is.
We can also get the keys this way.
So the summary now, there is more to learn about loops.
And in the next lecture's you will learn about other types of loops, how to stop the loop or skip elements.
We will also talk about a special loop variable, which has a lot of useful info about the loop itself,
like the current loop index.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.