File: /mnt/data/ghayatcom/ghayatcom-api/app/AppointmentReason.php
<?php
namespace App;
use Config;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Storage;
class AppointmentReason extends Model
{
protected $appends = ['reason_documents', 'reason_documents_str'];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function getReasonDocumentsStrAttribute()
{
$variableLibrary = new \App\Library\VariableLibrary;
$value = $this->reasons_document;
if ($value != null) {
$decodeData = json_decode($value);
/** @var array|null $decodeData */
if (count($decodeData)) {
$arr = $decodeData;
return $arr;
} else {
return null;
}
} else {
return null;
}
}
public function getReasonDocumentsAttribute()
{
$variableLibrary = new \App\Library\VariableLibrary;
$value = $this->reasons_document;
/** @var string $value */
if ($value != null) {
$decodeData = json_decode($value);
/** @var array|null $decodeData */
if (count($decodeData) != 0) {
$arr = $decodeData;
/** @var array $arr */
$out = [];
for ($i = 0; $i < count($arr); $i++) {
if (Config::get('filesystems.default') == 's3') {
$json = Storage::temporaryUrl('digimed/images/appointment/'.$arr[$i], now()->addMinutes(30));
} else {
$json = Storage::disk('public')->url('digimed/images/appointment/'.$arr[$i]);
}
array_push($out, $json);
}
return $out;
} else {
return null;
}
} else {
return null;
}
}
}