refactor: update model casts to use method syntax across multiple models.

This commit is contained in:
Yoga Pangestu 2026-02-19 11:09:08 +07:00
parent f6a1abfa0e
commit 4c444c703d
6 changed files with 49 additions and 31 deletions

View File

@ -16,7 +16,9 @@ class DelayedGood extends Model
protected $guarded = ['id']; protected $guarded = ['id'];
protected $casts = [ protected function casts(): array
{
return [
'stored_date' => 'date', 'stored_date' => 'date',
'payment_date' => 'date', 'payment_date' => 'date',
'quantity' => 'integer', 'quantity' => 'integer',
@ -25,6 +27,7 @@ class DelayedGood extends Model
'paid_amount' => 'integer', 'paid_amount' => 'integer',
'is_paid' => 'boolean', 'is_paid' => 'boolean',
]; ];
}
public function customer(): BelongsTo public function customer(): BelongsTo
{ {

View File

@ -13,9 +13,12 @@ class EggPrice extends Model
protected $guarded = ['id']; protected $guarded = ['id'];
protected $casts = [ protected function casts(): array
{
return [
'price' => 'integer', 'price' => 'integer',
]; ];
}
public function unit(): BelongsTo public function unit(): BelongsTo
{ {

View File

@ -14,7 +14,10 @@ class Expense extends Model implements HasMedia
protected $guarded = ['id']; protected $guarded = ['id'];
protected $casts = [ protected function casts(): array
{
return [
'expense_date' => 'date', 'expense_date' => 'date',
]; ];
} }
}

View File

@ -16,10 +16,13 @@ class FeedPurchase extends Model
protected $guarded = ['id']; protected $guarded = ['id'];
protected $casts = [ protected function casts(): array
{
return [
'purchase_date' => 'date', 'purchase_date' => 'date',
'total_price' => 'integer', 'total_price' => 'integer',
]; ];
}
public function items(): HasMany public function items(): HasMany
{ {

View File

@ -13,11 +13,14 @@ class FeedPurchaseItem extends Model
protected $guarded = ['id']; protected $guarded = ['id'];
protected $casts = [ protected function casts(): array
{
return [
'quantity' => 'integer', 'quantity' => 'integer',
'unit_price' => 'integer', 'unit_price' => 'integer',
'subtotal' => 'integer', 'subtotal' => 'integer',
]; ];
}
protected function formattedUnitPrice(): Attribute protected function formattedUnitPrice(): Attribute
{ {

View File

@ -13,13 +13,16 @@ class Order extends Model
protected $guarded = ['id']; protected $guarded = ['id'];
protected $casts = [ protected function casts(): array
{
return [
'order_date' => 'date', 'order_date' => 'date',
'egg_quantity' => 'integer', 'egg_quantity' => 'integer',
'unit_price' => 'integer', 'unit_price' => 'integer',
'total_amount' => 'integer', 'total_amount' => 'integer',
'discount' => 'integer', 'discount' => 'integer',
]; ];
}
public function customer(): BelongsTo public function customer(): BelongsTo
{ {