Adgower's avatar
Level 14

File URL

I am able to successfully upload a file to:

storage/app/public/documents/events/FILENAME.pdf

when I try to access it doesn't show in browser:

public function getUrl()
    {
        return Storage::disk('Event')->url($this->file_name);
    }

filesystems.php:

'Event' => [
            'driver' => 'local',
            'root' => storage_path('app/public/documents/events'),
            'url' => env('APP_URL').'/documents/events',
            'visibility' => 'public',
        ],

'links' => [
        public_path('storage') => storage_path('app/public'),
    ],

url generated:

https://laravel.local/documents/events/FILENAME.pdf

I ran storage:link and I see the file being uploaded, but the url its generating is wrong when I try to create a url for the file.

I'm using Homestead on windows 10, and I think I may have not done it right?

Any tips?

Thanks

0 likes
2 replies
WadeShuler's avatar
Level 1

Does it load with this URL?

https://laravel.local/storage/documents/events/FILENAME.pdf

public_path('storage') will be in your public directory as public/storage. It is essentially putting a directory (via symbolic link) in the root of your website as https://example.com/storage.

Try changing:

'url' => env('APP_URL').'/documents/events',

To:

'url' => env('APP_URL').'/storage/documents/events',

See if that works.

1 like
Adgower's avatar
Level 14

I change to what you said and I deleted the sym link and re ran php artisan storage:link on the vm in the root directory of the project and now it is working. Thank you.

Please or to participate in this conversation.