Laravel-传递多个变量来查看 [英] Laravel - Pass more than one variable to view
本文介绍了Laravel-传递多个变量来查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个站点,它的页面之一从数据库中创建了一个简单的人员列表.我需要在可以访问的变量中添加一个特定的人.
I have this site and one of its pages creates a simple list of people from the database. I need to add one specific person to a variable I can access.
如何修改return $view->with('persons', $persons);
行以将$ ms变量也传递给视图?
How do I modify the return $view->with('persons', $persons);
line to also pass the $ms variable to the view?
function view($view)
{
$ms = Person::where('name', 'Foo Bar');
$persons = Person::order_by('list_order', 'ASC')->get();
return $view->with('persons', $persons);
}
推荐答案
只需将其作为数组传递:
Just pass it as an array:
$data = [
'name' => 'Raphael',
'age' => 22,
'email' => 'r.mobis@rmobis.com'
];
return View::make('user')->with($data);
或者将它们链接起来,就像提到的@Antonio.
Or chain them, like @Antonio mentioned.
这篇关于Laravel-传递多个变量来查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文