For example, this is my file structure:
- MyProject
- app
- bootstrap
- config
- database
- node_modules
- pdfjs-dist
- build
- pdf.js
- build
- pdfjs-dist
- public
- upload
- documents
- solution_12.pdf
- documents
- upload
- resources
So when i type http://127.0.0.1:8000/uploads/documents/solution_12.pdf (1) into my web browser, it works fine, the web brower shows the pdf file. But when i type http://127.0.0.1:8000/node_modules/pdfjs-dist/build/pdf.js (2), i get not found error.
So can someone explain to my how does path in laravel works? How come the (1) link doesnt contain "public" route, (upload/documents/solution_12.pdf is stored inside public folder) but it still works? And why the (2) link returns not found?
2
Answers
Thanks for the answer. Can you tell me more about the vite part. I did a little reseach, and this is what i did:
At vite.config.js, inside defineConfig:
Inside app.js, i import the pdf.js script:
And to use this script, at my resources/views/instructor/course/edit.blade.php I add:
But the console say that my pdfjsLib cant be found. WHat did i do wrong?
Laravel serves the whole application from public/index.php file, that means when you run
php artisan serve
or host on the server/cloud, you have to point your domain root to/public
. so, the server can access all the files from thepublic
folder. if you wish to access files from thenode_modules
, you have to add the file paths to yourlaravel mix
orvite
configuration and that will copy/compile them into the public folder.For the best practices, the files should be uploaded in the
storage
folder and you can symlink it to thepublic
folder by executing thephp artisan storage:link
command.