php - Writing Json Array To Databases With Laravel -
i have array follows contained in $config:
array ( [1] => array ( [outlet] => facebook [thumbnail] => /images/catalog/modules/videoplayer/original.jpg [url] => http://www.google.com [copy] => test [vidurl] => http://www.youtube.com [poster] => none ) [2] => array ( [outlet] => facebook [thumbnail] => /images/catalog/modules/videoplayer/limon2.jpg [url] => http://www.yahoo.com [copy] => here copy [vidurl] => http://www.vimeo [poster] => no poster ) )
i'm converting json follows:
$module->configuration = json_encode($config,json_pretty_print);
everything saves db fine, producing object upon retrieval:
app\module object ( [table:protected] => modules [timestamps] => [connection:protected] => [primarykey:protected] => id [perpage:protected] => 15 [incrementing] => 1 [attributes:protected] => array ( [id] => 3 [title] => wddwdw [type] => socialfeed [configuration] => { "1": { "outlet": "facebook", "thumbnail": "\/images\/catalog\/admin\/no_image.png", "url": "wdwd", "copy": "wd", "vidurl": "wdw", "poster": "wd" }, "2": { "outlet": "facebook", ) [original:protected] => array ( [id] => 3 [title] => wddwdw [type] => socialfeed [configuration] => { "1": { "outlet": "facebook", "thumbnail": "\/images\/catalog\/admin\/no_image.png", "url": "wdwd", "copy": "wd", "vidurl": "wdw", "poster": "wd" }, "2": { "outlet": "facebook", ) [relations:protected] => array ( ) [hidden:protected] => array ( ) [visible:protected] => array ( ) [appends:protected] => array ( ) [fillable:protected] => array ( ) [guarded:protected] => array ( [0] => * ) [dates:protected] => array ( ) [dateformat:protected] => [casts:protected] => array ( ) [touches:protected] => array ( ) [observables:protected] => array ( ) [with:protected] => array ( ) [morphclass:protected] => [exists] => 1 )
as can see json broken. when retrieve $model->configuration broken:
{ "1": { "outlet": "facebook", "thumbnail": "\/images\/catalog\/admin\/no_image.png", "url": "wdwd", "copy": "wd", "vidurl": "wdw", "poster": "wd" }, "2": { "outlet": "facebook",
is there else need before writing json db make sure retrievable?
like said @scuzzy in comments, think have length problem here. either used varchar (255) store json in db, that's why it's cut, because string long or maybe it's var_dump or print didn't show , object fine.
i think it's first case, , suggest store serialized array instead of json in db.
Comments
Post a Comment