Мое определение схемы laravel для таблицы:
Код: Выделить всё
$table->binary('data')->nullable();
Код: Выделить всё
protected function casts(): array
{
return [
'data' => Compressed::class,
];
}
Код: Выделить всё
class Compressed implements CastsAttributes
{
public function get(Model $model, string $key, mixed $value, array $attributes): mixed
{
return blank($value) ? null : gzinflate($value);
}
public function set(Model $model, string $key, mixed $value, array $attributes): mixed
{
return blank($value) ? null : gzdeflate($value);
}
}
Код: Выделить всё
SQLSTATE[22021]: Character not in repertoire: 7 ERROR: invalid byte sequence for encoding "UTF8": 0x82 CONTEXT: unnamed portal parameter $1 (Connection: pgsql, SQL: update "table" set "data" =....
Код: Выделить всё
class Compressed implements CastsAttributes
{
public function get(Model $model, string $key, mixed $value, array $attributes): mixed
{
if (blank($value)) {
return null;
}
$my_bytea = stream_get_contents($value);
//$my_bytea = pg_unescape_bytea($my_bytea);
return gzinflate($my_bytea);
}
public function set(Model $model, string $key, mixed $value, array $attributes): mixed
{
return blank($value) ? null : pg_escape_bytea(gzdeflate($value));
}
}
Код: Выделить всё
gzinflate(): data error
Подробнее здесь: https://stackoverflow.com/questions/793 ... oquent-php
Мобильная версия