HEX
Server: nginx/1.24.0
System: Linux DGT-WORDPRESS-VM-SERVER 6.14.0-1014-azure #14~24.04.1-Ubuntu SMP Fri Oct 3 20:52:11 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 8.4.12
Disabled: NONE
Upload Files
File: /mnt/data/ghayatcom/ghayatcom-api/app/LabOrderData.php
<?php

namespace App;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class LabOrderData extends Model
{
    use HasFactory, SoftDeletes;

    protected $table = 'lab_order_data';

    protected $fillable = [
        'lab_order_id',
        'member_id',
        'item_id',
        'type',
        'item_name',
        'parameter',
        'mrp',
        'price'
    ];

    /**
     * Relationship with LabOrder.
     */
    public function labOrder()
    {
        return $this->belongsTo(LabOrder::class, 'lab_order_id');
    }

    /**
     * Relationship with Member (User).
     */
    public function member()
    {
        return $this->belongsTo(User::class, 'member_id'); // Assuming member is also a User
    }

    /**
     * Relationship with LabParameter when type is 2.
     */
    public function labParameter()
    {
        return $this->belongsTo(LabParameter::class, 'item_id');
    }

    /**
     * Relationship with LabPackage when type is 1.
     */
    public function labPackage()
    {
        return $this->belongsTo(LabPackage::class, 'item_id');
    }

    /**
     * Optional: If you still want a generic item relationship based on type.
     */
    public function item()
    {
        if ($this->type == 1) {
            return $this->belongsTo(LabPackage::class, 'item_id');
        } elseif ($this->type == 2) {
            return $this->belongsTo(LabParameter::class, 'item_id');
        }
        return null;
    }
}