mardi 1 novembre 2016

insert dynamic data in laravel-mongodb

i have json data from API like this

nama_lembaga: "Balai Besar Penelitian dan Pengembangan Pascapanen",
lembaga_induk: "Kementerian Pertanian",
kategori_lembaga: "Lembaga Pemerintah Kementerian (LPK)",
bentuk_lembaga: "Lembaga Tunggal",
fokus_bidang: "Pangan dan Pertanian",
tahun_penetapan: "2015",
tahun_daftar: "2014",

I need to store it in mongodb periodically using laravel 5.3 with this library laravel-mongodb I think the easy way is using create() method

$json = file_get_contents("API-address");
$obj = json_decode($json);
   foreach ($obj as $document) {
       puiModel::create((array)$document);
   }
}

but i get MassAssignmentException error which indicate i should declare the $fillable in model.

The problem is the indexes may be increased or reduced by the API owner. which means, i can not declare the $fillable value statically. How can i bypass the $fillable. ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire