From 7b252c797e6fdf334f724049b23fcd9d8239ff75 Mon Sep 17 00:00:00 2001 From: Arthur Monney Date: Wed, 16 Oct 2024 17:52:43 +0200 Subject: [PATCH] feat: update model attributes and factory (#303) --- packages/core/src/Models/Address.php | 7 ++---- packages/core/src/Models/Attribute.php | 6 +---- packages/core/src/Models/InventoryHistory.php | 13 ++++------ packages/core/src/Models/Product.php | 2 +- packages/core/src/Models/ProductRelation.php | 2 +- packages/core/src/Models/Review.php | 2 +- packages/core/src/Models/Setting.php | 2 +- packages/core/src/Models/User.php | 25 ++++++++----------- packages/core/src/Models/ZoneRelation.php | 2 +- 9 files changed, 24 insertions(+), 37 deletions(-) diff --git a/packages/core/src/Models/Address.php b/packages/core/src/Models/Address.php index 417c05902..337ab6bf7 100755 --- a/packages/core/src/Models/Address.php +++ b/packages/core/src/Models/Address.php @@ -22,6 +22,7 @@ * @property string | null $street_address_plus * @property string $postal_code * @property string $city + * @property AddressType $type * @property string | null $phone_number * @property bool $shipping_default * @property bool $billing_default @@ -48,10 +49,6 @@ class Address extends Model 'billing_default', ]; - protected $appends = [ - 'full_name', - ]; - protected $casts = [ 'billing_default' => 'boolean', 'shipping_default' => 'boolean', @@ -75,7 +72,7 @@ protected static function newFactory(): AddressFactory return AddressFactory::new(); } - public function fullName(): Attribute + protected function fullName(): Attribute { return Attribute::make( get: fn () => $this->first_name diff --git a/packages/core/src/Models/Attribute.php b/packages/core/src/Models/Attribute.php index f3c1283b7..babda101c 100755 --- a/packages/core/src/Models/Attribute.php +++ b/packages/core/src/Models/Attribute.php @@ -48,16 +48,12 @@ class Attribute extends Model 'type' => FieldType::class, ]; - protected $appends = [ - 'type_formatted', - ]; - public function getTable(): string { return shopper_table('attributes'); } - public function typeFormatted(): CastAttribute + protected function typeFormatted(): CastAttribute { return CastAttribute::make( get: fn () => self::typesFields()[$this->type->value] diff --git a/packages/core/src/Models/InventoryHistory.php b/packages/core/src/Models/InventoryHistory.php index 2a8c11990..ec6944633 100755 --- a/packages/core/src/Models/InventoryHistory.php +++ b/packages/core/src/Models/InventoryHistory.php @@ -13,11 +13,12 @@ /** * @property-read int $id * @property int $quantity - * @property int|null $old_quantity - * @property string|null $event - * @property string|null $description + * @property int | null $old_quantity + * @property string | null $event + * @property string | null $description * @property int $user_id * @property int $inventory_id + * @property string | int $adjustment */ class InventoryHistory extends Model { @@ -36,16 +37,12 @@ class InventoryHistory extends Model 'description', ]; - protected $appends = [ - 'adjustment', - ]; - public function getTable(): string { return shopper_table('inventory_histories'); } - public function adjustment(): Attribute + protected function adjustment(): Attribute { return Attribute::make( get: fn () => $this->old_quantity > 0 diff --git a/packages/core/src/Models/Product.php b/packages/core/src/Models/Product.php index c9af21eab..2af204a3f 100755 --- a/packages/core/src/Models/Product.php +++ b/packages/core/src/Models/Product.php @@ -41,7 +41,7 @@ * @property string | null $seo_description * @property \Carbon\Carbon | null $published_at * @property array | null $metadata - * @property-read int|null $stock + * @property-read int | null $stock */ class Product extends Model implements ReviewRateable, SpatieHasMedia { diff --git a/packages/core/src/Models/ProductRelation.php b/packages/core/src/Models/ProductRelation.php index 82f311c5d..3aee85310 100755 --- a/packages/core/src/Models/ProductRelation.php +++ b/packages/core/src/Models/ProductRelation.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphTo; -final class ProductRelation extends Model +class ProductRelation extends Model { public $timestamps = false; diff --git a/packages/core/src/Models/Review.php b/packages/core/src/Models/Review.php index 592bbc33c..95ffbf1b4 100755 --- a/packages/core/src/Models/Review.php +++ b/packages/core/src/Models/Review.php @@ -21,7 +21,7 @@ class Review extends Model { use HasFactory; - protected $guarded = []; + protected $guarded = ['id']; protected $casts = [ 'is_recommended' => 'boolean', diff --git a/packages/core/src/Models/Setting.php b/packages/core/src/Models/Setting.php index 4cb34cfc5..e9dc453fe 100755 --- a/packages/core/src/Models/Setting.php +++ b/packages/core/src/Models/Setting.php @@ -14,7 +14,7 @@ */ class Setting extends Model { - protected $guarded = []; + protected $guarded = ['id']; protected $hidden = [ 'locked', diff --git a/packages/core/src/Models/User.php b/packages/core/src/Models/User.php index db12c8caf..f832571fd 100755 --- a/packages/core/src/Models/User.php +++ b/packages/core/src/Models/User.php @@ -21,16 +21,16 @@ * @property-read int $id * @property-read string $full_name * @property-read string $picture - * @property string|null $first_name + * @property string | null $first_name * @property string $last_name * @property string $email * @property string $avatar_type - * @property string|null $avatar_location - * @property string|null $phone_number - * @property Carbon|null $email_verified_at - * @property Carbon|null $birth_date - * @property string|null $two_factor_recovery_codes - * @property string|null $two_factor_secret + * @property string | null $avatar_location + * @property string | null $phone_number + * @property Carbon | null $email_verified_at + * @property Carbon | null $birth_date + * @property string | null $two_factor_recovery_codes + * @property string | null $two_factor_secret */ class User extends Authenticatable { @@ -41,7 +41,7 @@ class User extends Authenticatable use Notifiable; use TwoFactorAuthenticatable; - protected $guarded = []; + protected $guarded = ['id']; protected $hidden = [ 'password', @@ -75,10 +75,7 @@ public static function boot(): void }); } - /** - * @return UserFactory|null - */ - protected static function newFactory() + protected static function newFactory(): UserFactory { return UserFactory::new(); } @@ -98,7 +95,7 @@ public function isVerified(): bool return $this->email_verified_at !== null; } - public function fullName(): Attribute + protected function fullName(): Attribute { return Attribute::make( get: fn () => $this->first_name @@ -107,7 +104,7 @@ public function fullName(): Attribute ); } - public function birthDateFormatted(): Attribute + protected function birthDateFormatted(): Attribute { return Attribute::make( get: fn () => $this->birth_date diff --git a/packages/core/src/Models/ZoneRelation.php b/packages/core/src/Models/ZoneRelation.php index 1430299f9..f7c8c76d5 100755 --- a/packages/core/src/Models/ZoneRelation.php +++ b/packages/core/src/Models/ZoneRelation.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphTo; -final class ZoneRelation extends Model +class ZoneRelation extends Model { public $timestamps = false;