55 lines
1.2 KiB
PHP
55 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class Order extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'order_number',
|
|
'customer_name',
|
|
'customer_email',
|
|
'customer_phone',
|
|
'shipping_street',
|
|
'shipping_number',
|
|
'shipping_postal_code',
|
|
'shipping_city',
|
|
'shipping_country',
|
|
'notes',
|
|
'status',
|
|
'subtotal',
|
|
'shipping_cost',
|
|
'total',
|
|
'payment_status',
|
|
'payment_method',
|
|
];
|
|
|
|
protected $casts = [
|
|
'subtotal' => 'float',
|
|
'shipping_cost' => 'float',
|
|
'total' => 'float',
|
|
];
|
|
|
|
public function items(): HasMany
|
|
{
|
|
return $this->hasMany(OrderItem::class);
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function getFormattedTotalAttribute(): string
|
|
{
|
|
return '€ '.number_format($this->total, 2, ',', '.');
|
|
}
|
|
}
|