Hasan alattar
Hasan alattar

Reputation: 339

Laravel public CSS stylesheet

I'm using this code to include my public style sheets:

<!DOCTYPE html>
<html>
    <head>
        <title>Laravel</title>
        <link rel="stylesheet" href="{{ asset('css/c_bootstrap.css') }}">
        <link rel="stylesheet" href="{{ asset('css/style_x.css') }}"  />
        <link rel="stylesheet" href="{{ asset('css/sb-admin.css') }}" />
    </head>
    <body>
        <!-- navbar -->
        @include ('layout.navbar')

        <div class="container">
            <div class="content">
            	@yield('content')
            </div>
        </div>
    </body>
</html>

In the view page source: enter image description here

when i click on it i get this: enter image description here

so it really looks like it works. However, it's just the error CSS from Laravel error page: enter image description here

so what's the mistake I'm doing here?

my folder:

|- public
|-|--- assets
|-|---|--- css
|-|---|---|--- c_bootstrap.css
|-|---|---|--- s.css
|-|---|---|--- sb-admin.css

Upvotes: 0

Views: 6209

Answers (3)

Hasan alattar
Hasan alattar

Reputation: 339

the problem was in .htaccess file

original:

Options +SymLinksIfOwnerMatch

RewriteEngine On
RewriteRule ^ index.php [L]

and after i edit it:

Options +SymLinksIfOwnerMatch

RewriteEngine On
#RewriteRule ^ index.php [L]
RewriteRule ^(.*)$ public/$1 [L]

my blade layout include must have assets:

    <link href="{{ asset('assets/css/c_bootstrap.css') }}" media="all" rel="stylesheet" type="text/css" />
    <link href="{{ asset('assets/css/style_x.css') }}" media="all" rel="stylesheet" type="text/css" />
    <link href="{{ asset('assets/css/sb-admin.css') }}" media="all" rel="stylesheet" type="text/css" />

Extra for asset function:

most of document online using asset function without including 'assets' in the path, I'm beginner in Laravel but i assume it calls the asset function in Routing: Illuminate/Routing/UrlGenerator.php#L202 in which i cant see where it append 'assets' in the url, so maybe they changed the function? i dont know

Upvotes: 1

Madhuri Patel
Madhuri Patel

Reputation: 1270

Place your assets in public directory and use the following to integrate css in laravel:

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

or

<link rel="stylesheet" type="text/css" href="{{ URL::to('css/style.css') }}">

Upvotes: 0

Bonish Koirala
Bonish Koirala

Reputation: 651

Try this for your css

<link rel="stylesheet" href="{{ asset('assets/css/c_bootstrap.css') }}"> <link rel="stylesheet" href="{{ asset('assets/css/style_x.css') }}" /> <link rel="stylesheet" href="{{ asset('assets/css/sb-admin.css') }}" />

Upvotes: 5

Related Questions