php - laravel 非法偏移类型
问题描述
这是我在控制器中的代码
$order = Order::with(['media','contact'])
->get();
这是我在视图中的代码,它工作正常
<label> {{__($order['details'])}} </label>
但是如果我将属性更改为时间戳属性,例如 'created_at' 、 'updated_at' 我会收到此错误
Illegal offset type
请注意:视图中的代码在 foreach 内
解决方案
问题是您将输出放入翻译函数中,而这些时间戳的输出是碳实例。
>>> __($u['created_at'])
PHP Warning: Illegal offset type in /app/vendor/laravel/framework/src/Illuminate/Translation/Translator.php on line 111
PHP Warning: Illegal offset type in isset or empty in /app/vendor/laravel/framework/src/Illuminate/Support/NamespacedItemResolver.php on line 25
PHP Warning: Illegal offset type in /app/vendor/laravel/framework/src/Illuminate/Support/NamespacedItemResolver.php on line 43
PHP Notice: Trying to access array offset on value of type null in /app/vendor/laravel/framework/src/Illuminate/Translation/Translator.php on line 330
PHP Notice: Undefined offset: 1 in /app/vendor/laravel/framework/src/Illuminate/Translation/Translator.php on line 117
PHP Notice: Undefined offset: 2 in /app/vendor/laravel/framework/src/Illuminate/Translation/Translator.php on line 117
=> Illuminate\Support\Carbon @1451606400 {#4467
date: 2016-01-01 00:00:00.0 UTC (+00:00),
}
但这里没有问题。
>>> $u['created_at']
=> Illuminate\Support\Carbon @1451606400 {#4465
date: 2016-01-01 00:00:00.0 UTC (+00:00),
}
>>>
推荐阅读
- javascript - 如何禁用“您所做的更改可能无法保存”弹出窗口
- .net - CefSharp 浏览器在登录屏幕上无法用作 WPF 屏幕保护程序
- javascript - 如何使用javascript在代码中调用函数?
- debian - 如何解决 MediaWiki 1.35.0 安装错误 1044
- python - gmsh:找不到命令
- bash - 使用 bash 脚本变量将 PSQL 查询作为 CSV 输出到 STDOUT
- r - 计算 R 中 beta 的 alpha 参数
- php - 在 docker 中安装 powercli 的问题
- c# - 控制台中的并行多行输出
- c++ - 具有 self 类型对象的 C++ 类的默认构造函数