You can have a special route that reads and returns the image. For example a simple closure route like this:
There are two approaches depending on the privacy of your files you can use any one of below.
1) Using dedicated controller to serve images:
Controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Storage;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Response;
class FileController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public static function getFile($fileName){
$path = storage_path() . '/' . $filename;
if(File::exists($path)){
return Response::download($path);
}
else
abort(404);
}
}
Route
Route::get('/file/{file_name}','FileController@getFile');
Now you can access a file called let's say abc.jpg
from this url /file/abc.jpg
2) Using symbolic link
If your files does not require any authentication or any processing this method is best and fasr with respect to Controller
Create a symbolic link between a subfolder in your storage directory and public directory.
In linux you can use following command:
ln -s /path_to_storage_directory/file /path_to_public_directory/files
In Windows use following command:
mklink /j /path_to_storage_directory/file /path_to_public_directory/files
In Windows if you don't want to use CMD this is a standalone application to create symlinks : Symlinker