PHP-larvel返回字符串而不是数组(JSON)

PHP-larvel返回字符串而不是数组(JSON),php,laravel,Php,Laravel,我有一个名为crappeddocumentfield的模型,它有以下$casts设置: protected $casts = [ 'content' => 'array' ]; 迁移过程如下所示: Schema::create('cropped_document_fields', function(Blueprint $table){ $table->increments('id'); $table->unsignedInteger('docu

我有一个名为
crappeddocumentfield
的模型,它有以下
$casts
设置:

protected $casts = [
    'content' => 'array'
];
迁移过程如下所示:

Schema::create('cropped_document_fields', function(Blueprint $table){
      $table->increments('id');
      $table->unsignedInteger('document_id');
      $table->json('content')->nullable();
});
在我的数据库中,内容列似乎像字符串一样存储:

"{\"1\": [{\"row\": \"Bill Tc\\n\"}, {\"row\": \"Nathar\\n\"}, {\"row\": \"75839\\n\"}]}"
如果我重复这一点:

$document = CroppedDocumentField::Find(56);
dd(is_array($document->content));
这返回false

当我将JSON插入数据库时,我从一个.txt文件中读取它,该文件包含JSON字符串:

{"1": [{"row": "Bill Tc\n"}, {"row": "Nathar\n"}, {"row": "75839\n"}]}
然后我插入:

$file = "mytext.txt";
$content = file_get_contents($file);

//Add the text content
$this->document->cropped()->create([
     'content' => $content
]);
在我的文档模型中,我只是与
crappeddocumentfield
模型有关系:

//Document.php:
public function cropped()
{
    return $this->hasMany(CroppedDocumentField::class);
}

我做错了什么

我在我的项目中尝试将json转换为数组,结果正如预期的那样,我认为问题在于存储内容的方式。请尝试将其更改为此,并让我知道:

//Add the text content
$this->document->cropped()->create([
     'content' => json_decode($content) // convert string to json
]);

@Tarasovych啊,修复了-这是一个输入错误MySQL列的数据类型是什么?是VARCHAR吗?数据类型是
JSON
-将更新我的问题以包括迁移。我相信问题是因为
file\u get\u contents
返回字符串,所以数据是这样存储的。我在我的项目中有
json
专栏,直接将其转换为数组。啊,太完美了!这会将字符串转换为有效的JSON对象。谢谢