状态码:500个格式错误的UTF-8字符,可能是Laravel编码错误

时间:2018-09-21 09:01:37

标签: php laravel-5.3

每当我尝试使用控制器在Postman中创建发布请求时,都会收到该错误,我认为正是此Model引起了问题。我该如何解决该错误?我认为json_decode引起了问题。请帮我。谢谢

<?php

namespace App;

use Illuminate\Database\Eloquent\SoftDeletes;

class Group extends BaseModel
{
    use SoftDeletes;

    /**
     * The connection name for the model.
     *
     * @var string
     */
    protected $connection = 'mysql-core';

    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = [
        'created_at',
        'updated_at',
        'deleted_at'
    ];

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'uuid',
        'organization_id',
        'name',
        'description',
        'allowed_members',
    ];

    public function setAllowedMembersAttribute($value)
    {
        if (empty($value)) {
            $value = [];
        }

        $this->attributes['allowed_members'] = json_encode($value, JSON_HEX_QUOT | JSON_HEX_TAG);
    }

    public function getAllowedMembersAttribute($value)
    {
        if ($value === null) {
            return [];
        }

        return json_decode($value);
    }
}

0 个答案:

没有答案