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/LabOrderDocument.php
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Storage;

class LabOrderDocument extends Model
{
    protected $table = 'lab_order_documents';

    protected $fillable = [
        'lab_order_id',
        'document_name',
        'document_path',
    ];

    protected $appends = ['document_url']; // Add document_url as an appended attribute

    public function getDocumentUrlAttribute()
    {
        $value = $this->document_path;

        if ($value) {
            if (Config::get('filesystems.default') === 's3') {
                return Storage::temporaryUrl(
                    'digimed/lab_reports/' . $this->lab_order_id . '/' . $value,
                    now()->addMinutes(30)
                );
            } else {
                return Storage::url('digimed/lab_reports/' . $this->lab_order_id . '/' . $value);
            }
        }

        return null;
    }
}