42 lines
836 B
PHP
42 lines
836 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Order extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $fillable = [
|
|
'customer_id',
|
|
'status',
|
|
'total',
|
|
'payment_status',
|
|
'notes',
|
|
];
|
|
|
|
/**
|
|
* Get the customer that owns the order.
|
|
*/
|
|
public function customer()
|
|
{
|
|
return $this->belongsTo(User::class, 'customer_id');
|
|
}
|
|
|
|
/**
|
|
* Get the products for the order.
|
|
*/
|
|
public function products()
|
|
{
|
|
return $this->belongsToMany(Product::class, 'order_products')
|
|
->withPivot('quantity', 'price', 'total')
|
|
->withTimestamps();
|
|
}
|
|
}
|