This commit is contained in:
50
app/Models/Order.php
Normal file
50
app/Models/Order.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?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 => 'Не указан',
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user