0

Eghad, the laravel documentation is lacking. So if you want to have css in a package for the package views specifically, and you figure out how to publish those assets, how do you specify the path when calling them with the asset() helper?

e.g.:

I have a packages with a resources/assets/css/mystyles.css I tell the Service Provider to publish my assets under 'vendor/myorg/mypackage'

// Publishing assets.
$this->publishes([
    __DIR__.'/../resources/assets' => public_path('vendor/myorg/mypackage'),
], 'mypackage.assets');

I have a view in my package where I want it to display that css, what do I put in the asset() call? 'css/mystyles.css'? 'vendor/myorg/mypackage/css/mystyles.css'? something even more convoluted?

<link href="{{ asset('????/css/mystyles.css') }}" rel="stylesheet" />
Scott
  • 7,983
  • 2
  • 26
  • 41

2 Answers2

3

Read here

Your package user must publish your assets. They will be placed at (in your case) to vendor/myorg/mypackage - you specify that patch at provider.

After publishing you can reach asset by asset('vendor/myorg/mypackage/css/mystyles.css')

Maksim
  • 2,653
  • 2
  • 13
  • 28
  • thanks, I figured that out with some tinkering after posting but still wasn't sure that was the best-practices method. – Scott Aug 03 '21 at 22:48
-1

helper function asset() points to the public folder in Laravel directories, you can move your stylesheet files to the public directory and by helper asset() access any style file you want

Mohsen Nazari
  • 1,281
  • 1
  • 3
  • 13
AMIN
  • 1
  • 3