69 lines
1.6 KiB
PHP
69 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use App\Models\ModuleVmware;
|
|
|
|
class Order extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected $table = 'orders';
|
|
|
|
protected $guarded = [];
|
|
public function customer()
|
|
{
|
|
return $this->belongsTo(Customer::class);
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function discount()
|
|
{
|
|
return $this->belongsTo(Discount::class);
|
|
}
|
|
|
|
/** Line items that make up this order. */
|
|
public function orderItems()
|
|
{
|
|
return $this->hasMany(OrderItem::class, 'order_id');
|
|
}
|
|
|
|
/** Invoice generated from this order. */
|
|
public function invoice()
|
|
{
|
|
return $this->hasOne(Invoice::class, 'order_id');
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// Helpers
|
|
// -------------------------------------------------------------------------
|
|
|
|
public function getStatusLabelAttribute(): string
|
|
{
|
|
return match ($this->status) {
|
|
'pending' => 'Chờ xử lý',
|
|
'processing' => 'Đang xử lý',
|
|
'completed' => 'Hoàn tất',
|
|
'cancelled' => 'Đã hủy',
|
|
default => ucfirst($this->status),
|
|
};
|
|
}
|
|
|
|
public function payment()
|
|
{
|
|
return $this->belongsTo(Payment::class);
|
|
}
|
|
|
|
public function moduleVmwares()
|
|
{
|
|
return $this->hasMany(ModuleVmware::class, 'order_id');
|
|
}
|
|
}
|