bugs fix ambil path di list provider
This commit is contained in:
@@ -133,12 +133,46 @@ class ClaimReportController extends Controller
|
||||
)
|
||||
->get();
|
||||
$results['request_files'] = $request_files;
|
||||
|
||||
// Jika path kosong, kembalikan null
|
||||
if (!$row->path) {
|
||||
return null;
|
||||
}
|
||||
// $documents = DB::table('files')
|
||||
// ->where('fileable_type', 'App\Models\ClaimRequest')
|
||||
// ->where('fileable_id', $claimRequestId)
|
||||
// ->select('original_name', \DB::raw("CONCAT('" . env('APP_URL') . "/storage/', path) as path"), 'type')
|
||||
// ->orderBy('id', 'desc')
|
||||
// ->get();
|
||||
|
||||
$documents = DB::table('files')
|
||||
->where('fileable_type', 'App\Models\ClaimRequest')
|
||||
->where('fileable_id', $claimRequestId)
|
||||
->select('original_name', \DB::raw("CONCAT('" . env('APP_URL') . "/storage/', path) as path"), 'type')
|
||||
->orderBy('id', 'desc')
|
||||
->get();
|
||||
->where('fileable_type', 'App\Models\ClaimRequest')
|
||||
->where('fileable_id', $claimRequestId)
|
||||
->select('id', 'original_name', 'path', 'source', 'type')
|
||||
->orderBy('id', 'desc')
|
||||
->get()
|
||||
->map(function ($row) {
|
||||
// default null kalau tidak ada path
|
||||
if (!$row->path) {
|
||||
$row->path = null; // atau bisa $row->url = null
|
||||
return $row;
|
||||
}
|
||||
|
||||
if ($row->source === 's3') {
|
||||
try {
|
||||
$row->path = Storage::disk('s3')->temporaryUrl(
|
||||
$row->path,
|
||||
now()->addMinutes(60)
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$row->path = Storage::disk('s3')->url($row->path);
|
||||
}
|
||||
} else {
|
||||
$row->path = Storage::disk('public')->url($row->path);
|
||||
}
|
||||
|
||||
return $row;
|
||||
});
|
||||
$results['documents'] = $documents;
|
||||
|
||||
return Helper::responseJson($results);
|
||||
|
||||
@@ -130,8 +130,27 @@ class DataServiceMonitoring extends JsonResource
|
||||
->get();
|
||||
if ($document){
|
||||
foreach($document as $d){
|
||||
// Jika path kosong, kembalikan null
|
||||
if (!$row->path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Cek nilai 'source'. Jika 's3', gunakan disk S3.
|
||||
// Selain itu (termasuk null atau 'local'), gunakan disk 'public'.
|
||||
if ($row->source === 's3') {
|
||||
try {
|
||||
$path = Storage::disk('s3')->temporaryUrl(
|
||||
$row->path,
|
||||
now()->addMinutes(60) // expired 1 jam
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$path = Storage::disk('s3')->url($row->path); // fallback kalau public
|
||||
}
|
||||
} else {
|
||||
$path = Storage::disk('public')->url($row->path);
|
||||
}
|
||||
$arr_document[]= [
|
||||
'path' => env('APP_URL') . '/storage/lab_result/' . $d->name . '.' . $d->extension,
|
||||
'path' => $path,
|
||||
'type' => $d->type,
|
||||
'original_name' => $d->original_name,
|
||||
'name' => $d->name,
|
||||
@@ -194,8 +213,28 @@ class DataServiceMonitoring extends JsonResource
|
||||
->get();
|
||||
if ($document){
|
||||
foreach($document as $d){
|
||||
// Jika path kosong, kembalikan null
|
||||
if (!$row->path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Cek nilai 'source'. Jika 's3', gunakan disk S3.
|
||||
// Selain itu (termasuk null atau 'local'), gunakan disk 'public'.
|
||||
if ($row->source === 's3') {
|
||||
try {
|
||||
$path = Storage::disk('s3')->temporaryUrl(
|
||||
$row->path,
|
||||
now()->addMinutes(60) // expired 1 jam
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$path = Storage::disk('s3')->url($row->path); // fallback kalau public
|
||||
}
|
||||
} else {
|
||||
$path = Storage::disk('public')->url($row->path);
|
||||
}
|
||||
|
||||
$arr_document[]= [
|
||||
'path' => env('APP_URL') . '/storage/lab_result/' . $d->name . '.' . $d->extension,
|
||||
'path' => $path,
|
||||
'type' => $d->type,
|
||||
'original_name' => $d->original_name,
|
||||
'name' => $d->name,
|
||||
|
||||
Reference in New Issue
Block a user