<?php
class PostsMigration extends Migration
public function up()
{
Schema::table('posts', function (Blueprint $table) {
$table->json('show_in')->nullable();
});
}
}
<?php
class Post extends Model
{
//cast to json when storing, and array when retrieving
protected $casts = [
'show_in' => 'array',
];
//set default value for json column array
protected $attributes = [
'show_in' => '["sidebar_left", "sidebar_right", "content", "top"]'
];
//set default value for json column object
protected $attributes = array(
'show_in' => '{}'
);
}