有一个名为“faq”的语言文件,其中列出了所有常见问题和答案。
我不知道如何从这些语言文件中执行foreach循环。
我的faq.php语言文件:
return [
'faq_1' => 'Question here',
'faq_1_ans' => 'Answer here',
'faq_2' => 'Question here',
'faq_2_ans' => 'Answer here',
];
如何将其转化为foreach循环?我真的不知道从哪里开始。
答案 0 :(得分:4)
您可能想要更改结构
return [
'faq_1' => [
'q' => "Question",
'a' => "Answer Here"
],
'faq_2' => [
'q' => "Question",
'a' => "Answer Here"
],
];
甚至
return [
[
'q' => "Question",
'a' => "Answer Here"
],
[
'q' => "Question",
'a' => "Answer Here"
],
];
这样你就可以循环:
$faqs = Lang::get('faq');
foreach($faqs as $faq)
{
echo "question: " . $faq['q'];
echo "answer: " . $faq['a']:
}
答案 1 :(得分:0)
您还可以使用助手trans()
例如在刀片模板中:
@if(Auth::user()->isAdmin || Auth::user()->isConfirmation)
<script>
// ... some pusher configuration
// subscribe to the channel 'new-cr-from-part'
let channel = pusher.subscribe('new-cr-from-part');
// listen for event BroadcastNotificationCreated
channel.bind(
'Illuminate\\Notifications\\Events\\BroadcastNotificationCreated',
function(data) {
console.log(data);
// Some javascript
receiveCRNotification();
});
</script>
@endif