D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
forge
/
developers.ghanempharmacy.com
/
app
/
Models
/
Filename :
ProductBundleItem.php
back
Copy
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; class ProductBundleItem extends Model { protected $fillable = [ 'bundle_id', 'product_id', 'quantity', ]; protected $casts = [ 'quantity' => 'integer', ]; /** * Get the bundle this item belongs to */ public function bundle(): BelongsTo { return $this->belongsTo(ProductBundle::class, 'bundle_id'); } /** * Get the product */ public function product(): BelongsTo { return $this->belongsTo(Product::class, 'product_id'); } /** * Get item total price */ public function getTotalPrice(): float { if (!$this->product) { return 0; } return $this->product->unit_price * $this->quantity; } }