Код: Выделить всё
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));
Когда я вставляю 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
]);
Код: Выделить всё
//Document.php:
public function cropped()
{
return $this->hasMany(CroppedDocumentField::class);
}
Подробнее здесь: https://stackoverflow.com/questions/562 ... array-json
Мобильная версия