Reputation:
Hello every one I am working with laravel and developing my first package and I need to add some css and javascript files with my package can any one answer me what is the right way to do this task.
Upvotes: 3
Views: 3803
Reputation: 23231
Whenever I write Laravel packages, I strive to keep the JavaScript inline.
When I can't do that, I will use the GitHub raw URL for the JavaScript/CSS asset and load that directly in the Laravel view.
That way whenever anyone uses my Laravel packages and forgets or doesn't know about doing the php artisan vendor:publish
command (~85%), it still just 'works'.
Upvotes: 2
Reputation: 1045
As @laravel levaral suggested you need to publish assets first afterwards in your root directory you will find public folder. Inside public you can make 'js' and 'css' folders in which you can store those files.
In order to access your assets through out the whole laravel project you just need to call it from your blade file using asset()
For js file:-
E.g:- <script src="{{ asset('js/app.js') }}"></script>
Likewise for css file:-
E.g:- <link href="{{ asset('css/app.css') }}" rel="stylesheet">
Upvotes: 1
Reputation: 15941
You cannot directly add the assets from Your Laravel Package for that you have publish()
assets first.
In your Service Provider
/**
*
* @return void
*/
public function boot()
{
$this->publishes([
__DIR__.'/path/to/assets' => public_path('vendor/courier'),
], 'public');
}
Then use it in your views using asset()
Hope this helps
Upvotes: 3