Laravel - Foreach loop from a language file?
Ad
have a language file called "faq" which lists all the frequently asked questions and answers.
I have no idea how to do a foreach loop from those language files.
My faq.php language file:
return [
'faq_1' => 'Question here',
'faq_1_ans' => 'Answer here',
'faq_2' => 'Question here',
'faq_2_ans' => 'Answer here',
];
How can I make that into a foreach loop? I really don't know where to start.
Ad
Answer
Ad
You might want to change the structure
return [
'faq_1' => [
'q' => "Question",
'a' => "Answer Here"
],
'faq_2' => [
'q' => "Question",
'a' => "Answer Here"
],
];
or even
return [
[
'q' => "Question",
'a' => "Answer Here"
],
[
'q' => "Question",
'a' => "Answer Here"
],
];
this way you can loop:
$faqs = Lang::get('faq');
foreach($faqs as $faq)
{
echo "question: " . $faq['q'];
echo "answer: " . $faq['a']:
}
Ad
source: stackoverflow.com
Related Questions
Ad
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad