laravel 非法偏移类型

这是我在控制器中的代码

  $order = Order::with(['media','contact'])
        ->get();

这是我在视图中的代码,它工作正常

 <label> {{__($order['details'])}} </label>

但是如果我将属性更改为时间戳属性,例如 'created_at' 、 'updated_at' 我收到此错误

Illegal offset type

注意:视图中的代码在foreach里面


元芳怎么了
浏览 171回答 1
1回答

慕哥9229398

问题是您将输出放入翻译函数中,并且这些时间戳的输出是一个碳实例。>>> __($u['created_at'])PHP Warning:&nbsp; Illegal offset type in /app/vendor/laravel/framework/src/Illuminate/Translation/Translator.php on line 111PHP Warning:&nbsp; Illegal offset type in isset or empty in /app/vendor/laravel/framework/src/Illuminate/Support/NamespacedItemResolver.php on line 25PHP Warning:&nbsp; Illegal offset type in /app/vendor/laravel/framework/src/Illuminate/Support/NamespacedItemResolver.php on line 43PHP Notice:&nbsp; Trying to access array offset on value of type null in /app/vendor/laravel/framework/src/Illuminate/Translation/Translator.php on line 330PHP Notice:&nbsp; Undefined offset: 1 in /app/vendor/laravel/framework/src/Illuminate/Translation/Translator.php on line 117PHP Notice:&nbsp; Undefined offset: 2 in /app/vendor/laravel/framework/src/Illuminate/Translation/Translator.php on line 117=> Illuminate\Support\Carbon @1451606400 {#4467&nbsp; &nbsp; &nbsp;date: 2016-01-01 00:00:00.0 UTC (+00:00),&nbsp; &nbsp;}但这里没有问题。>>> $u['created_at']=> Illuminate\Support\Carbon @1451606400 {#4465&nbsp; &nbsp; &nbsp;date: 2016-01-01 00:00:00.0 UTC (+00:00),&nbsp; &nbsp;}>>>&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP