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.

Anil Kumar Sahu
  • 567
  • 2
  • 7
  • 27

2 Answers2

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.

Anil Kumar Sahu
  • 567
  • 2
  • 7
  • 27
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.

Ritesh Khatri
  • 1,253
  • 13
  • 29