63 lines
1.3 KiB
PHP
63 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class OrderItem extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/**
|
|
* The table associated with the model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $table = 'order_items';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $fillable = [
|
|
'order_id',
|
|
'item_id',
|
|
'item_name',
|
|
'item_price',
|
|
'quantity',
|
|
'total_price',
|
|
'cooked'
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast.
|
|
*
|
|
* @var array<string, string>
|
|
*/
|
|
protected $casts = [
|
|
'item_price' => 'decimal:2', // Pastikan presisi 2 desimal
|
|
'total_price' => 'decimal:2', // Pastikan presisi 2 desimal
|
|
'quantity' => 'integer',
|
|
'created_at' => 'datetime',
|
|
'updated_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* Get the order that owns the order item.
|
|
*/
|
|
public function order()
|
|
{
|
|
return $this->belongsTo(Order::class, 'order_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* Get the actual menu item associated with the order item.
|
|
*/
|
|
public function item()
|
|
{
|
|
return $this->belongsTo(Items::class, 'item_id', 'id');
|
|
}
|
|
}
|