Uploading files and storing path in database

Posted 2 years ago by jontyjago

I'm struggling with uploading files and then easily accessing them.

I've configured the storage link so anything placed in storage/app/public is visible through however this is where I'm having problems

The following code in my controller

$path = $request->file('docfile')->store('public');

        return $path;

saves the files to the correct directory but the $path returned is


so if I save this to the database and try to link to that later the file will not be found, as the storage folder is linked, not the public folder.

If I don't put a folder name in the controller:

$path = $request->file('docfile')->store('');

        return $path;

then the $path variable only contains the file name but it gets saved to storage/app so is not found by Using 'storage' as the folder in the controller would save the file to storage/app/storage.

What I would like is to save just the file name in the database and for the file to be saved in the correct location so it is visible from

Going forward I would like to be able to configure a custom file structure like but I need to get the basics right first!

Please sign in or create an account to participate in this conversation.