Search code examples
phpcsslaravel-5assets

Laravel assets return 404 on localhost


I am pretty new to Laravel. I use Ubuntu and cloned an app from GitHub on home folder. When I run the app with php artisan serve I don't see the page styled. Ctrl-u shows the source with no problem but I have 404 errors in the console regarding everything under the asset folder. console warnings can be seen here

my 000_default.conf file is

/etc/apache2/sites-enabled/000-defult.conf                 
<VirtualHost *:80>

        ServerAdmin webmaster@localhost
        DocumentRoot ~/_/www/easymove/public

        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/laravel>
                AllowOverride All
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>


Contents of the webpack.mix.js at the app root are as follows:

const mix = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.js('resources/js/app.js', 'public/js')
   .sass('resources/sass/app.scss', 'public/css');

Solution

  • You need to add some rules to your webpack.mix.js to handle your assets.

    At current, your webpack will only compile JS files. You need to have it also copy over files and directories for your images and compile your css based on where its currently residing:

    https://laravel.com/docs/7.x/mix#copying-files-and-directories

    https://laravel.com/docs/7.x/mix#working-with-stylesheets