index.php in public folder is not loading js and css files
Hi all,
My project is working well with index.php in root, and accessible via this:
http://localhost/ecommerce/ecommerce/ecommerce/
I tried to run php artisan serve and it showed an error : require_once(C:\xampp\htdocs\ecommerce\ecommerce\ecommerce/public/index.php): failed to open stream: No such file,
then i moved the index.php file from root to public folder, it works but the and js and css files are not being loaded, all i can see its just plain text
=index.php file after moving it to public folder,
require __DIR__.'/../vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'/../bootstrap/app.php';
Hi @zool if previously your index was in root (which is wrong at all), I think you have links to your css/js like
/public/js/my.js. Then you move index file back to public, so, really links should be now like /js/my.js (without public prefix)
Hey @silencebringer, thanks a lot for your help ! You are a life saver !
Your solution worked for me, however i'm a littler confused here how it worked. My css and js files were pointing to public/frontend/etc files, then i removed the public/ directory as you mentioned, because i moved the index.php file to public folder, my question is, i could get how index.php is related to my css and js files ? I mean where it catches up the public directory. I appreciate your help !
Hey @laracoft , thanks a lot for your help !
I removed public from my css and js files that were pointing to public folder and it worked fine!
I should avoid moving the index.php file from public directory in next projects ;)