我正试着按照一个小的幼体教程来做.

在我的应用程序中,我有一个名为HomeController的控制器.

在我的家庭控制器中,我有以下inf索引函数

public function index()
    {
        try {
            //get autheticated users selected organisation
            $organisation = $this->getSelectedOrganisationByUser(Auth::user());

            //set application timezone
            $this->setApplicationTimezone($organisation);

            $this->setSiteConnection($organisation);
            $this->setGAConnection($organisation);

            if ($organisation->disabled) {
                Auth::logout();
                return redirect(route('login'));
            }
            //sales today
            $sum='23';
            return view('dashboard.index')
                ->with('organisation',$organisation,'sum',$sum);
        } catch (\Throwable $exception) {
            \Sentry\captureException($exception);
        }
    }

在这里,我try 将这个$sum值发送到我的Blade 并显示它.但是,每次我try 在Blade 式服务器上显示此值时,我都会收到$SUM IS UNDEFINITED错误.

我试着在Blade 上重复这一点,如下所示:

{{ $sum }}

我应该做什么更改,才能在我的Blade 上显示它.

我费了很大劲,但还是想不出解决办法

推荐答案

来自/Illuminate/View/View.php的方法with()仅接受两个参数.

要发送多个变量,您可以

//Call with() for each variable
return view('dashboard.index')
                ->with('organisation',$organisation)
                ->with('sum',$sum);
//use an array as second parameter of view
return view('dashboard.index', ['organisation' => $organisation,'sum' => $sum]);
//use compact to create the array using the variable name
return view('dashboard.index', compact('organisation', 'sum'));
//use an array as first parameter in with (using compact or not)
return view('dashboard.index')->with(compact('organisation', 'sum'));

Php相关问答推荐

无法使用PHP DomDocument找到IMG元素

Woocommerce自定义变体html表仅显示带值的列

PHP,ZipArchive删除一个空文件?

具有重叠捕获组的PHP正则表达式

基于不用于变体的产品属性隐藏多个WooCommerce发货方式

使用列入黑名单的单词和自定义业务逻辑的组合将特定的子字符串包装在HTML标记中

PHP-带POST验证的for循环

Apache只允许index.php-不从根目录工作

SFTP在PHP(phpseclib3\Net\SFTP)-过滤目录列表结果服务器端可能吗?类似于psftp中的LS命令?

如何在WordPress REST API中判断应用程序密码

WooCommerce在收据页面获取产品下载URL

文件::Files()响应返回空对象数组

根据页面以及是否在促销,向 WooCommerce 中显示的价格添加前缀

从图像URL中获取文件扩展名?

PHP Symfony 在测试.env文件中将接口自动装配作为构造函数参数,但使用接口的特定类

如何从此字符串创建 Carbon 对象:2022-06-21T05:52:46.648533678Z?

按前 3 列对二维数组中的行数据进行分组,然后用逗号连接每组中的其余列

将 HTML 表单链接到 SQLite 数据库

如何限制for循环php中的条目数

htaccess 无限循环问题