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;
}
}