Kamran
Kamran

Reputation: 71

Loading assets from *.blade.php in Laravel

Laravel 5.4 here.

I added test.css file under public/css/ and then made a call in my layout.blade.php like this:

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

but the asset does not get loaded.

My problem is that i am trying to run css for jquery-ui. I downloaded jquery-ui-bundle via npm and then required it in resources/assets/js/bootstrap.js. Widget works, but the calendar shows up without styles. So i try to add styles manually by referencing them directly through the template. Unfortunately, this doesn't help.

Upvotes: 1

Views: 33079

Answers (2)

Parth Vora
Parth Vora

Reputation: 4114

You can directly put js/CSS into your public folder if they don't require compiling first (which is in your case) - There is no harm in that

But if you want to go as per recommendation:

  • Pull library using NPM,

  • Add js/CSS into gulpfile.js which you want to copy to the public folder:

    elixir((mix) => {

    mix.sass('app.scss')
    .webpack('app.js')
    .mix.copy('node_modules/foo/bar.css', 'public/css/bar.css');
    

    });

    https://laravel.com/docs/5.4/mix#copying-files-and-directories

  • Run npm run command

  • And then include into your blade view like:

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

Upvotes: 3

SWastik Thapaliya
SWastik Thapaliya

Reputation: 325

For simplicity, you can just simply copy source file to public\css or public\js and link it to your project file. In other words, link

rel="stylesheet" type="text/css" href={{asset('css/bootstrap.css')}}

Upvotes: 2

Related Questions