0

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
6
  • yours assets folder spelling is wrong. Commented Nov 6, 2018 at 6:28
  • its just here in the post, edited @bonish koirala Commented Nov 6, 2018 at 6:29
  • have you tried this asset('assets/css/c_bootstrap.css') something like that for other files too? Commented Nov 6, 2018 at 6:32
  • doesnt work, the router doesnt allow to access files becasue its somehow trying to parse the url. im very new to laravel, im trying to put css directly to public not compile it. Commented Nov 6, 2018 at 6:43
  • Can you view your c_bootstrap.css page as html? Commented Nov 6, 2018 at 6:50

3 Answers 3

5

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') }}" />

Sign up to request clarification or add additional context in comments.

Comments

1

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

2 Comments

If this was your solution, then it indicates the DocumentRoot is misconfigured for Apache. The document root for a Laravel project should be the public/ folder, otherwise you may be unintentionally exposing sensitive configuration files, logs, uploads, etc. to the internet.
its not in public because it was in some folder because the project was in subdomain .. the apache config files in /etc was right, but .htaccess misconfigured..
0

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') }}">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.