1

I have a ImageController like this:

$image = Image::where('id', $id)->first();

return [
    'image' => $image,
    'image_360' => $image['360']
];

The previous lines return to the browser the following:

{
    "image": {
        "id": 1,
        "name": "default.jpg",
        "360": 1,
    },
    "image_360": null
}

The Image migration:

$table->increments('id');
$table->string('name');
$table->boolean('360');

The Image model:

class Image extends Model
{
    protected $fillable = ['name', '360'];

    protected $casts = [
        '360' => 'boolean'
    ];
}

Why $images['360'] returns null if its value is true?

LF00
  • 27,015
  • 29
  • 156
  • 295
cespon
  • 5,630
  • 7
  • 33
  • 47

1 Answers1

1

Here is the workaround way: I've tryed many ways but havenot get a direct way to access the number value as descripted in this post

return [
    'image' => $image,
    'image_360' => array_values($image->toArray())[2];
];
Community
  • 1
  • 1
LF00
  • 27,015
  • 29
  • 156
  • 295