2
votes

I'm using Laravel 5.3 and on some pages the css isn't loading. I tried the suggestions from this question, but they didn't help.

This is what I did so far:

  1. I installed Laravel on wamp inside www/lblog directory so I access laravel's main page via http://localhost:8080/lblog/

  2. To get rid of the "public" part from the URL I moved the index.php and htaccess files from the "public" directory to the root directory and changed two lines in index.php like this:

    require DIR.'./bootstrap/autoload.php'; $app = require_once DIR.'./bootstrap/app.php';

  3. In "resources/views/layouts/app.blade.php" I have the styles linked like this:

I tried to remove the / before the "css", it didn't work that way either.

The main page is ok, but if I go to http://localhost:8080/lblog/login for example, the style is broken.

1
Using custom paths for laravel is really a pain. However if you must you need to make sure that your paths.php reflects the correct paths. Having said this, you should instead use a vhost on Apache and not move any files around. Set your vhost root to the laravel public directory. - apokryfos
Also since you're starting fresh I suggest you use laravel 5 which offers a lot more that laravel 3. - apokryfos
Sorry, I meant laravel 5.3 The problem is when I didn't move the files from the public dir, on some pages the style were still broken. - PapT
I still suggest you use a vhost because Laravel does not (nor did it ever) officially support moving the public directory around, so it's a pain to get working. My guess is you'll need to make sure that the asset() method still generates the correct URL and use that method to make your paths uniform. - apokryfos
Is there a good reason to move the public folder from its default pos? - John

1 Answers

1
votes

Don't hack the core, use it as it is which is recommended.

Use laravel's built in helpers for generating URL for your assets that are on public directory

<link rel="stylesheet" href="{{ asset('css/styles.css') }}">

which will properly generate URL for your files that are on public directory