I personally created a route for that.
I use it to serve images. In addition to that I use http://image.intervention.io/ to server the images.
Route:
$this->get('/images/files/{file}','MediaServerController@serveImages')
->where(['file'=>'.*']);
Controller
class MediaServerController extends Controller{
public function serveImages ($file)
{
$storagePath = storage_path('app/images/'.$file);
if( ! \File::exists($storagePath)
return view('errorpages.404');
return \Image::make($storagePath)->response();
}
}
Basically what this does is to take
The Url http://example.com/images/files/image.jpg
The controller checks if the file (Image.jpg) exists in the storage (app/images/image.jpg) folder if the intervention image library renders the images and creates a response.
It will work for any depth of subfolders as well for ex.
http://example.com/images/files/subfolder/image.jpg
Now the controller will look into your subfolder (app/images/subfolder/image.jpg) in your images folder.
For other files than Images you could use the Response::download()
Hope that helps
Now, you can secure it how ever you want with a middleware on the route / controller for instance.
Down side of this approach is that yo have to boot your application every time you access an image. The response will take much longer compared to the response from your web server (apache/nginx) who would serve the image normally for you if they were in the public folder.
You have to make this trade of security vs performance.
Alex