这是我在控制器中的代码
$order = Order::with(['media','contact'])
->get();
这是我在视图中的代码,它工作正常
<label> {{__($order['details'])}} </label>
但是如果我将属性更改为timestamp属性(例如'created_at','updated_at'),则会出现此错误
Illegal offset type
请注意:视图中的代码位于foreach内部
答案 0 :(得分:0)
问题是您将输出放入转换函数中,而这些时间戳的输出是一个碳实例。
>>> __($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),
}
>>>