Skip to content

Commit

Permalink
Cleanup ProductOption accessor/mutator and fix fields casting (#1783)
Browse files Browse the repository at this point in the history
  • Loading branch information
wychoong authored Aug 19, 2024
1 parent e03dfb7 commit 63313d2
Showing 1 changed file with 3 additions and 22 deletions.
25 changes: 3 additions & 22 deletions packages/core/src/Models/ProductOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace Lunar\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\AsCollection;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Casts\AsArrayObject;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
Expand Down Expand Up @@ -39,8 +38,8 @@ class ProductOption extends BaseModel implements SpatieHasMedia
* @var array
*/
protected $casts = [
'name' => AsCollection::class,
'label' => AsCollection::class,
'name' => AsArrayObject::class,
'label' => AsArrayObject::class,
'shared' => 'boolean',
];

Expand All @@ -52,24 +51,6 @@ protected static function newFactory(): ProductOptionFactory
return ProductOptionFactory::new();
}

public function getNameAttribute(?string $value = null): mixed
{
return json_decode($value);
}

protected function setNameAttribute(mixed $value): void
{
$this->attributes['name'] = json_encode($value);
}

protected function label(): Attribute
{
return Attribute::make(
get: fn (string $value) => json_decode($value),
set: fn ($value) => json_encode($value),
);
}

/**
* Define which attributes should be
* protected from mass assignment.
Expand Down

0 comments on commit 63313d2

Please sign in to comment.