Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update model attributes and factory #303

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions packages/core/src/Models/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -48,10 +49,6 @@ class Address extends Model
'billing_default',
];

protected $appends = [
'full_name',
];

protected $casts = [
'billing_default' => 'boolean',
'shipping_default' => 'boolean',
Expand All @@ -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
Expand Down
6 changes: 1 addition & 5 deletions packages/core/src/Models/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 5 additions & 8 deletions packages/core/src/Models/InventoryHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Models/ProductRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Models/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Review extends Model
{
use HasFactory;

protected $guarded = [];
protected $guarded = ['id'];

protected $casts = [
'is_recommended' => 'boolean',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Models/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
class Setting extends Model
{
protected $guarded = [];
protected $guarded = ['id'];

protected $hidden = [
'locked',
Expand Down
25 changes: 11 additions & 14 deletions packages/core/src/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -41,7 +41,7 @@ class User extends Authenticatable
use Notifiable;
use TwoFactorAuthenticatable;

protected $guarded = [];
protected $guarded = ['id'];

protected $hidden = [
'password',
Expand Down Expand Up @@ -75,10 +75,7 @@ public static function boot(): void
});
}

/**
* @return UserFactory|null
*/
protected static function newFactory()
protected static function newFactory(): UserFactory
{
return UserFactory::new();
}
Expand All @@ -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
Expand All @@ -107,7 +104,7 @@ public function fullName(): Attribute
);
}

public function birthDateFormatted(): Attribute
protected function birthDateFormatted(): Attribute
{
return Attribute::make(
get: fn () => $this->birth_date
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Models/ZoneRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading