I am trying to import a CSS file into one of my Laravel views but it's not being included for some reason.
This is is what I have in my view file:
@extends('layouts.admin')
@section('style')
<link href="{{asset('public/css/my-css-file.css')}}" rel="stylesheet"/>
@endsection
@section('content')
<div class="content">view content.....</div>
@endsection
If I include my css file in layout file it works fine but I want it applied to one view only. Any help please? Thanks.
My Answer:
You can import a CSS file in a Laravel Blade view by using the `asset()` helper function to generate the correct URL for the CSS file. Here's an example of how you can include a CSS file in your Blade view:
html
@extends('layouts.admin')
@section('style')
@endsection
Make sure that the CSS file is located in the `public/css` directory of your Laravel project. If the CSS file is located in a different directory, you will need to adjust the path in the `asset()` function accordingly.
Also, ensure that your `layouts.admin` view file includes the necessary HTML `` section where the CSS file will be included. If the CSS file is still not being imported, try clearing your browser cache or using a different browser to see if the changes take effect.
Rate this post
4 of 5 based on 9750 votesComments