Search code examples
laravelpdfbloblaravel-filesystem

How to serve the data returned from laravel Storage::disk('private')->get($file) as PDF


My question is about the problem in link below :

Understanding file storage and protecting contents Laravel 5

I need to use the same method mentioned in above example but instead of an image I need to provide a download link for PDF file or a link to open PDF file in browser and I can't do that because, as mentioned in above example's comments The Storage::disk('private')->get($file) returns the CONTENT of the file NOT the URL.

Please tell me how can I convert the row data (content of file) to a file and provide the link for the users inside the view.


Solution

  • According to the Laravel documentation you can simply use the download method on the Storage facade.

    From your controller, return the result of the command.

    return Storage::disk('private')->download($file);