dev
dev

Reputation: 27

Why my css file is not loading in laravel?

I am very new to Laravel, I have done the login blade file and I included CSS files but it's not loading CSS files, can you please help me where I made a mistake ..?

users.blade.php

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

Upvotes: 0

Views: 2068

Answers (1)

Aseem Lalfakawma
Aseem Lalfakawma

Reputation: 191

You're trying to access the resources folder, which is not exposed to the public, you'll have to compile your css so it lives in the public folder, which is the folder that anyone(including your frontend) can access using https://your-url.tld/{public file path}. There are 2 ways in which you can have your user.css file available for to your frontend:

One:

You can import your user.css file to the existing resources/css/app.css file:

/* app.css file */
@import "../path/to/user.css";

Two:

You can compile user.css to a separate file, in case you want to use that file specifically on another layout or blade file instead of mixing it globally with the app.css file:

// webpack.mix.js file
mix.js('...')
    .css('resources/css/user.css', 'public/css');

Then in your layout file:

// app.blade.php file
<link rel="stylesheet" href="{{ asset('css/user.css') }}">

Hope it helps.

Upvotes: 1

Related Questions