1

I am using below code

dd(URL(env("UserFolder") . \Auth::user()->UserID . "/" . \Auth::user()->UniqueFileName));

which gives below result.

http://localhost/SportsApp/public/storage/User17/9.png

Is there any way to remove public directory from this Url: http://localhost/SportsApp/public/storage/User17/9.png?

I meant Is there any inbuilt method that gives me Url for Storage directory?

Pankaj
  • 9,749
  • 32
  • 139
  • 283

3 Answers3

0

You need to use correct web server VH configuration. Set public directory as root for Laravel project VH.

The restart server and use URLs like http://localhost/img/User17/9.png?

Community
  • 1
  • 1
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
0

By default users can't access your storage folder by security reasons, they only can access public. So if you wish to return some file from storage you should do it manually

Route::get('get-file', function() {
    return response()->file(storage_path().'path_to_your_file');
});

or you can move your user's files into public dir and get links on it using asset

asset(env("UserFolder") . \Auth::user()->UserID . "/" . \Auth::user()->UniqueFileName));
huuuk
  • 4,597
  • 2
  • 20
  • 27
0

Your webserver DocumentRoot should point to /path/to/you/laravel/project/public

You could do something like this

$publicPath = 'img/avatar/generic.svg';    
public_path($publicPath);


public_path() // returns the system path to your document root  
$publicPath // is the path using your public/ as root

Combine those and you get the full path, e.g. "/var/www/project/public/img/avatar/generic.svg"