'', 'message' => '' ]; } /** @var CanRenderDocument */ private $canRenderDocument; /** @var JWT */ private $manager; /** * RenderDocumentLogic constructor. * @param CanRenderDocument $canRenderDocument * @param JWT $manager */ public function __construct(CanRenderDocument $canRenderDocument, JWT $manager) { $this->canRenderDocument = $canRenderDocument; $this->manager = $manager; } /** * @param Request $request * @return JsonResponse * @throws AccessForbiddenException * @throws RequestValidationException * @throws ResourceNotFoundException * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ public function logic(Request $request) : JsonResponse { $file = $request->route('fileName'); $this->canRenderDocument->passes(); $filesystemDriver = Storage::getDefaultDriver(); if($filesystemDriver === 's3'){ if(!Storage::disk('s3')->exists($file)) { throw new ResourceNotFoundException(); } return $this->response(['src' => explode('.', $file)[1] == 'pdf' ? chunk_split(base64_encode(Storage::disk('s3')->get($file))) : Storage::disk('s3')->get($file) ]); } else{ if(!Storage::disk('documents')->exists($file)) { throw new ResourceNotFoundException(); } return $this->response(['src' => explode('.', $file)[1] == 'pdf' ? chunk_split(base64_encode(Storage::disk('documents')->get($file))) : Storage::disk('documents')->get($file) ]); } } }