Replies: 1 comment
-
FYI, I am working around this with the following subclass now: <?php
declare(strict_types=1);
namespace App\Casts;
use Spatie\SchemalessAttributes\Casts\SchemalessAttributes as CastsSchemalessAttributes;
class SchemalessAttributes extends CastsSchemalessAttributes
{
public function set($model, $key, $value, $attributes)
{
$result = parent::set($model, $key, $value, $attributes);
if ($result === '[]') {
return null;
}
return $result;
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When I save a new entity to the database, as long as I never touch the SchemalessAttributes property, it will get written as
null
to the database. But as soon as I touch the property, it will get written as[]
to the database; a mere$entity->property_bag
call is sufficient without actually doing anything with the property. I would like to have it always written asnull
to the database, even when theSchemalessAttributes
field has been instantiate (provided it is empty, of course).I understand this might not be built in; if I have to implement this myself, would it be possible to simply subclass
Casts\SchemalessAttributes
and override itsset
method to returnnull
instead of[]
when the value is empty? Or is there a better way to do this? Or would that maybe have other unintended side effects?Beta Was this translation helpful? Give feedback.
All reactions