How to define and use JSON data type in Eloquent?

In your migrations you can do something like:

$table->json('field_name');

And in your model you add the field to the $casts property to instruct Eloquent to deserialize it from JSON into a PHP array:

class SomeModel extends Model
{
    protected $casts = [
        'field_name' => 'array'
    ];
}

Source: https://laravel.com/docs/5.1/eloquent-mutators#attribute-casting

Note: This is also relevant answer for Laravel 5.6

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)