在模型上设置 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

相关文章:

  • 2021-11-13
  • 2022-12-23
  • 2022-01-05
  • 2021-10-25
  • 2021-08-03
  • 2022-12-23
  • 2021-06-19
猜你喜欢
  • 2022-02-08
  • 2021-12-06
  • 2022-01-16
  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
  • 2022-01-08
相关资源
相似解决方案