Laravel-modules: How to link to css or js files in laravel module?

Created on 3 Aug 2018  路  3Comments  路  Source: nWidart/laravel-modules

Hi guys!
I have a problem. I need a help.
I want to link to the css or js file inside the module.
When I try to run the command
{{Module :: asset ('blog: css / blog.css')}} in the module's app.blade.php file.
is on the head tag but it does not work.
I have public module as follows
php artisan module: publish
But everything is not better.
Here is my directory structure:

     -Blog
          -Assets
              -css
                  blog.css
          -Providers
              BlogServiceProvider.php
          -Resource
              -views
                  app.blade.php

Do I need to configure anything in BlogServiceProvider.php file?
Thanks for all the help.
I wish you a happy day

Most helpful comment

Your first step is good
I have followed it and now it is separated from main laravel source.
In the module's view file I just need to
<link rel = "stylesheet" href = "{{asset ('modules / blog / css / blog.css')}}">
and in the webpack.mix.js
mix.copyDirectory (__dirname + '/ Assets', '../../public/modules/blog');
Everything is much clearer now.
thank you @KABBOUCHI

All 3 comments

you can use Laravel Mix to copy blog.css to the public folder and use mix('css/blog.css')

// Modules/Blog/webpack.mix.js
const { mix } = require('laravel-mix');

mix.setPublicPath('../../public');
mix.copy( __dirname + '/Assets/blog.css', 'css/blog.css');

or using php

<style>
{!! file_get_contents(Module::find('blog')->getPath() . '/Assets/blog.css'); !!}
</style>

Your first step is good
I have followed it and now it is separated from main laravel source.
In the module's view file I just need to
<link rel = "stylesheet" href = "{{asset ('modules / blog / css / blog.css')}}">
and in the webpack.mix.js
mix.copyDirectory (__dirname + '/ Assets', '../../public/modules/blog');
Everything is much clearer now.
thank you @KABBOUCHI

@dang-tien if your issue has been resolved, plz close it :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cyberbaseza picture cyberbaseza  路  4Comments

Levivb picture Levivb  路  4Comments

ojasseh picture ojasseh  路  3Comments

djoudi picture djoudi  路  4Comments

alexandretaz picture alexandretaz  路  3Comments