Laravel - 传递多个变量来查看 [英] Laravel - Pass more than one variable to view

查看:33
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆