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

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Carbon;
use Storage;
use App\PrescriptionRouteLists;

/**
 * App\Prescription
 *
 * @property mixed $status
 */
class Prescription extends Model
{
    use SoftDeletes;

    protected $fillable = ['id', 'appointment_id', 'type', 'prescription_code', 'status', 'qrcode', 'prescription_date', 'created_at', 'created_by', 'updated_by', 'deleted_by'];

    protected $appends = ['qrcode_url'];

    protected $hidden = ['created_by', 'updated_by', 'deleted_by', 'deleted_at', 'updated_at'];

    public function appointment(): BelongsTo
    {
        return $this->belongsTo(Appointment::class, 'appointment_id', 'id');
    }

    public function prescriptionDetails(): HasOne
    {
        return $this->hasOne(PrescriptionDetails::class, 'prescription_id', 'id');
    }

    public function prescriptionRequests(): HasOne
    {
        return $this->hasOne(PrescriptionRequest::class, 'prescription_id', 'id')->latest();
    }

    public function prescriptionRouteList(): HasMany
    {
        return $this->hasMany(PrescriptionRouteLists::class, 'prescription_id', 'id');
    }

    public function getQrcodeUrlAttribute()
    {
        $S3Library = new \App\Library\S3Library;
        $digimedFile = ($S3Library->s3Url($this->qrcode, null, 'digimed/images/prescription/'.$this->appointment_id));

        return (isset($this->qrcode)) ? $digimedFile : '';
        //  return (isset($this->qrcode)) ? Storage::url('app/public/prescription/' . $this->appointment_id . '/' . $this->qrcode) : "";
    }

    public function getPdfAttribute($value)
    {
        // return (isset($value)) ? Storage::url('app/public/prescription/' . $value) : "";
        $S3Library = new \App\Library\S3Library;
        $digimedFile = ($S3Library->s3Url($value, null, 'digimed/images/prescription'));

        return (isset($value)) ? $digimedFile : '';
    }
}