dimanche 9 décembre 2018

Malformed UTF-8 characters, possibly incorrectly encoded with json data

Getting error when I try to save json data in json field.

From my database schema,

$table->string('config_slug');
$table->json('config')->nullable();

From controller,

public function store(Request $request)
{
        $data = [];
        foreach ($request->tenure_type as $key => $value) {
            $data[utf8_encode($key)] = utf8_encode($request->tenure_type[$key]);
        }

        $tenure = Config::where('config_slug', 'tenure_type')->first();
        if ($tenure) {
            $tenure->config = $data;
            $tenure->save();
        } else {
            $config = new Config();
            $config->config_slug = 'tenure_type';
            $config->config = $data;
            $config->save();
        }
        return Config::where('config_slug', 'tenure_type')->first();
}

POST data,

{"tenure_type":{"abcdemo":"abc demo"}}

Error screenshot, error



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire