cyjobes's avatar

File upload/access

I'm learning Laravel 5.3 as I work on a project. I am stuck on some things and was hoping for guidance.

The idea: Each entry is a project. Admin user uploads a file or set of files associated with a project Normal users can click a link from the list of file(s) to download and view

When I created the upload I used Storage::makeDirectory(PATH_TO_FILE) to create the location for the file and storeAs(PATH, FILENAME) to place the file to that location. The path, in this case is '/project_assets/ID/FILENAME' The file is then saved to '/storage/app/project_assets/ID/FILENAME'

Now I need to access this file from a page that a normal user can access. However I get an error when I try to do this - NotFoundHttpException in RouteCollection.php line 161:

As I mentioned above, I am learning as I go, and may have gone about this the wrong way.

Any guidance is appreciated.

Thanks, Cy

0 likes
6 replies
goatshark's avatar

@cyjobes What route is being hit to produce the NotFountHttpException? Is that present in your routes file (web or api depending on what you're up to).? If so, what is that route?

cyjobes's avatar

@goatshark Thanks for the help. I finally got it.

Changed filesystem.php default to public. Ran the php artisan storage:link and made a few code changes. Now I can access the files.

Still kinda confused on how this is working. Thanks again.

goatshark's avatar

I still have to think it through each time. Personally, I get little bubbles of temporary confusion dealing with the path under storage/ being more deeply nested than the path under /public... It makes thinking through the results of php artisan storage:link a little slow for me.

I also find Laravel's path helpers pretty...helpful. https://laravel.com/docs/5.3/helpers

Please or to participate in this conversation.