2

In my project that is developed in laravel, i am trying to use a style.css file using blade engine. but it's not working for me anybody have better idea let me know. Here is my code sample

      <link href="{{ asset('/css/style.css')}}" rel="stylesheet" type="text/css">
it's tag is not working but when i'm us following it's working.

      <link href="{{ asset('public/css/style.css')}}" rel="stylesheet" type="text/css">

now i want to now best practices of adding css files and how to include other files. like i've file header.blade.php it hold all css file link now i want to include header.blade.php in home.blade.php file both file in view directory.

3
  • stackoverflow.com/a/37507278/1227923 Commented Feb 22, 2018 at 11:43
  • If you need to have public/ in your assets path you did something wrong. public should be your server's DocumentRoot Commented Feb 22, 2018 at 11:50
  • how to find where is my mistake? Commented Feb 22, 2018 at 11:57

2 Answers 2

2

Placed your css file inside laravel_project/public/css folder and use the link it into your view like:

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

I think this will help you Thanks.

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

8 Comments

i'm try this code and my all css file in public/css folder but this code is not working. but when i'm try following it's working fine. <link href="{{asset('public/css/style.css')}}" rel="stylesheet" type="text/css"/>
Dear Rana Raheel Tariq just try to view page source code and click on the css link and let me know the file it is getting successfully or not
one more thing you are using php artisan serve command or just you are running your project by accessing the public folder
in source view when i'm open style.css link it's not open. and i'm copy .htaccess file in main folder and access our project directly localhost/mylaravelpojectfoldername
Dear just try to run project by run php artisan serve command because this {{asset('css/style.css')}} will work only by this if you want for manual access the project you should use <?php $url_path=asset(""); $current_url=url()->current(); ?> <link rel="stylesheet" href="{{$url_path}}/css/style.css">
|
0

I think your style.css is stored in public/css directory thats why it allow second you have provided.

And now your header.blade.php holds all your css files so you have to follow laravel's structure in layout if u have app.blade.php or any layout then its perfect otherwise you have to make it own

Sample app.blade.php (stored at views/layout/)

<!DOCTYPE html>
<html>
@include('layouts.partials.header') // path to your header.blade.php
@yield('content')
@include('layouts.partials.footer') // path to your footer.blade.php
</html>

Now this is your layout and you can use your layout and your header as well as footer in your view file like i am creating one blog_list.blade.php which is stored at views directory

blog_list.blade.php

@extends('layouts.app') // we are extending app.blade.php
@section('content')
  // here whatever your content
@endsection

You can find more details on laravel's official site laravel-5.4

I hope it helps you. thank you.

2 Comments

Thank You for commenting i'll try @include function
ohkay... if it help than do not forget to mark it with up vote.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.