canRenderDocument = $canRenderDocument; } protected function notification(): array { return [ 'title' => '', 'message' => '' ]; } /** @var CanRenderDocument */ private $canRenderDocument; /** * @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(); if(!Storage::disk('documents')->exists($file)) { throw new ResourceNotFoundException('Requested File not found'); } return $this->response(['src' => explode('.', $file)[1] == 'pdf' ? chunk_split(base64_encode(Storage::disk('documents')->get($file))) : Storage::disk('documents')->get($file) ]); } }