0
votes

this is my code in the controller

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

and this is my code in the view and it work fine

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

but if I change the attribute to timestamp attribute like 'created_at' , 'updated_at' I got this error

Illegal offset type

note that: the code in the view is inside foreach

1
We need to see more code here. This line doesn't seems to throw the error you gotFelippe Duarte
Why are you using array access, to access a model object? Can you provide your for loop please?Kurt Friars
Nvm, somehow did not realize laravel let you do eitherKurt Friars
Note: In your current code, $order is a Collection; ->get() returns multiple Order objects. If you're not already, you need to loop them, like @foreach($orders as $order), and prefer to use object syntax: $order->details instead of array syntax $order['details'] (although both are allowed, objects is preferred)Tim Lewis

1 Answers

0
votes

The issue is that you are putting the output into the translation function, and the output of those timestamps is a carbon instance.

>>> __($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),
   }

But no issue here.

>>> $u['created_at']
=> Illuminate\Support\Carbon @1451606400 {#4465
     date: 2016-01-01 00:00:00.0 UTC (+00:00),
   }
>>>