30 lines
729 B
PHP
30 lines
729 B
PHP
<?php
|
|
|
|
namespace App\Casts;
|
|
|
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Compressed implements CastsAttributes
|
|
{
|
|
public function get(Model $model, string $key, mixed $value, array $attributes): mixed
|
|
{
|
|
if (blank($value)) {
|
|
return null;
|
|
}
|
|
|
|
if (is_resource($value)) {
|
|
rewind($value);
|
|
$value = stream_get_contents($value);
|
|
}
|
|
// $value = pg_unescape_bytea($value);
|
|
|
|
return gzinflate($value);
|
|
}
|
|
|
|
public function set(Model $model, string $key, mixed $value, array $attributes): mixed
|
|
{
|
|
return blank($value) ? null : pg_escape_bytea(gzdeflate($value));
|
|
}
|
|
}
|