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);
|
||||
|
||||
Reference in New Issue
Block a user