In laravel 10 / php 8.2 app I keep results of some request in database, json field.
When data read from db(mysql 8) on the page it looks like :
I save data in method as :
public static function write( string $key, ?string $data = '' ): KeyData {
$keyData->data = $data;
...
$keyData->save();
return $keyData;
}
In KeyData model data set in casts :
protected $casts = [ 'data' => 'array', ...
and in migration defined as :
$table->json('data')->nullable();
Checkin data in db I see a lot of slashing and “n” chars :
and when I read saved prior html data from db I see a lot of symbols on the page which I do not need:
I tried to clear saved data with trim, stripslashes methods – it partly helped, but not completely.
How correctly save and read html in mysql json field ?