File: /mnt/data/ghayatcom/ghayatcom-api/app/UserUpload.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Library\S3Library;
use Storage;
use Config;
class UserUpload extends Model
{
use HasFactory;
protected $fillable = [
'user_id', 'address', 'contact_number', 'type', 'chronic_conditions',
'allergies', 'medications', 'past_surgeries', 'insurance_card', 'lab_results', 'file_path'
];
protected $visible = ['file_path_url', 'type', 'file_path', 'created_at'];
protected $appends = ['file_path_url'];
public function user()
{
return $this->belongsTo(User::class);
}
public function getFilePathUrlAttribute()
{
$value = $this->file_path;
if ($value != null) {
if (Config::get('filesystems.default') == 's3') {
$url = Storage::temporaryUrl('digimed/images/patient-documents/' . $this->user_id . '/' . $value, now()->addMinutes(30));
} else {
$url = Storage::url('app/public/images/documents/' . $this->user_id . '/' . $value);
}
return $url;
} else {
return null;
}
}
}