I wanted to update our answer since this changed a bit. We keep all our files outside the webroot as it was getting a little tricky to make sure we had all the right paths when mixing windows and mac dev platforms.
We went with keeping the files in a static folder outside the webroot for security. And we pull the files via php on page load with lazyloading to keep the bandwidth down.
So here's the code:
Route Declaration
//Image Controller
Route::get('images/{image}', 'PhotoController@get_image_from_directory')->name('images');
The Actual Function
/**
* Routes helper function to show the images
* Has some minimal string parsing for security.
* Consider locking this down to mime type
*/
public function get_image_from_directory($image = null){
//simple directory traversall protection
$image = str_replace('../', '', $image);
$file_info = new SplFileInfo($image);
$extension = $file_info->getExtension();
$extension = strtolower($extension);
//unsupported extension check
if($extension != 'jpg' and $extension != 'jpeg' and $extension != 'png' and $extension != 'gif'){
return;
}
$app_file_path = $_ENV['APP_FILE_PATH'];
$path = $app_file_path . '/' . $image;
if (file_exists($path)) {
return Response::download($path);
}
}
And actually showing the image
<img class="lazyload" src="{{ asset('default.jpg') }}" data-src="{{ route('images', $file->filename) }}" width="100%"></img>