我有一個名為 的模型CroppedDocumentField,其$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 插入到我的數據庫時,我從包含 JSON 字符串的 .txt 文件中讀取它:{"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]);在我的文檔模型中,我只是與CroppedDocumentField模型有關系://Document.php:public function cropped(){ return $this->hasMany(CroppedDocumentField::class);}我在這里做錯了什么?
- 1 回答
- 0 關注
- 276 瀏覽
添加回答
舉報
0/150
提交
取消