在模型上设置 accessor 和 mutator,将数组转为 json,并设置 json 选项。
class User extends Model { public function setOptionAttribute($option) { $this->attributes['option'] = json_encode($option, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } public function getOptionAttribute($value) { return json_decode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } }
Refer:Laravel_unicode编码问题
doc: https://laravel.com/docs/8.x/eloquent-mutators
Link:https://www.cnblogs.com/farwish/p/13764108.html