ext ? "{$file->name}.{$file->ext}" : null; $content = Base::json2array($content ?: []); if (in_array($file->type, ['word', 'excel', 'ppt'])) { if (empty($content)) { return Response::download(resource_path('assets/statics/office/empty.' . str_replace(['word', 'excel', 'ppt'], ['docx', 'xlsx', 'pptx'], $file->type)), $name); } return Response::download(public_path($content['url']), $name); } if (empty($content)) { $content = match ($file->type) { 'document' => [ "type" => $file->ext, "content" => "", ], default => json_decode('{}'), }; if ($download) { abort(403, "This file is empty."); } } else { $path = $content['url']; if ($file->ext) { $res = File::formatFileData([ 'path' => $path, 'ext' => $file->ext, 'size' => $file->size, 'name' => $file->name, ]); $content = $res['content']; } else { $content['preview'] = false; } if ($download) { $filePath = public_path($path); if (isset($filePath)) { return Response::download($filePath, $name); } else { abort(403, "This file not support download."); } } } return Base::retSuccess('success', [ 'content' => $content ]); } }