Files
tehnobox/app/Models/Order.php
ssww23 0ee9f05416
Some checks failed
Deploy / deploy (push) Has been cancelled
1
2026-03-17 01:59:00 +03:00

64 lines
1.4 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Order extends Model
{
use HasFactory;
protected $fillable = [
'user_id',
'status',
'payment_method',
'total',
'items_count',
'customer_name',
'email',
'phone',
'address',
'comment',
];
protected function casts(): array
{
return [
'total' => 'decimal:2',
'items_count' => 'integer',
];
}
public function user()
{
return $this->belongsTo(User::class);
}
public function items()
{
return $this->hasMany(OrderItem::class);
}
public function getPaymentMethodLabelAttribute(): string
{
return match ($this->payment_method) {
'card_transfer' => __('Перевод по реквизитам (на карту)'),
default => __('Не указан'),
};
}
public function getStatusLabelAttribute(): string
{
return match ($this->status) {
'new' => __('Новый'),
'processing' => __('В обработке'),
'paid' => __('Оплачен'),
'shipped' => __('Отправлен'),
'completed' => __('Завершен'),
'cancelled' => __('Отменен'),
default => (string) $this->status,
};
}
}