Posted: 04-12-2017

Laravel 5.5 return a file from storage as a response

Laravel 5.5.22 add support for response() and download() methods on the file system.
In some situations where you might want to return a file in the controller from storage or force a download:

 

class DocumentController extends Controller
{
    public function show(Document $document)
    {
        // Return the document as a response
        return Storage::response($document->path);

        // Use a custom filename
        return Storage::response($document->path, 'sweet.pdf');

        // Force the file to download
        return Storage::download($document->path);
    }
}