Whats the right way to store JSON in a database with Laravel? -
i have json data want store in database. ideally, data should automatically decoded when retreive database , automatically encoded when store in database.
how can this?
use accessors , mutators, attribute called foobar add these 2 functions in eloquent model:
public function getfoobarattribute($value){ return json_decode($value); } public function setfoobarattribute($value){ $this->attributes['foobar'] = json_encode($value); }
Comments
Post a Comment