简体   繁体   English

如何在 laravel package 中给出资产路径?

[英]how to give asset path in laravel package?

I have developed laravel package.我开发了 laravel package。 which has view example is here有视图示例在这里

index.blade索引刀片


    <!DOCTYPE html>
    <html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    
    <head>
        <meta charset="utf-8">
    
        <!-- CSRF Token -->
        <meta name="csrf-token" content="{{ csrf_token() }}">
    
        <title>{{ config('app.name', 'ColdxLogistics') }} - @yield('title')</title>
    
        <meta name="description" content="Login page example">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    
        <!--end::Layout Skins -->
        <link rel="shortcut icon" href="{{asset('media/logos/favicon.ico')}}" /> 
      
    </head>
    
    
    <!--begin::Page Scripts(used by this page) -->
    <script src="{{asset('js/pages/crud/forms/editors/tinymce.js')}}" type="text/javascript"></script>
    
    <script src="{{asset('js/main.js')}}" type="text/javascript"></script>
    
    
    @yield('scripts')
    
    
    </body>
    
    </html>

You can here are many javascript and css files.您可以在这里查看许多 javascript 和 css 文件。 I want to make asset folder for package from where ican load these files.我想为 package 创建资产文件夹,我可以从中加载这些文件。 like laravel have public directory.像 laravel 有公共目录。

Which Approach i should use?我应该使用哪种方法?

You do not link to your packages assets folder, you need to publish the assets like in the documentation , then link to them normally using asset() .您不链接到您的包资产文件夹,您需要像在文档中一样发布资产,然后通常使用 assets asset()链接到它们。

In your packages service provider, you need to add:在您的包裹服务提供商中,您需要添加:

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    $this->publishes([
        __DIR__.'/path/to/assets' => public_path('vendor/yourpackagename'),
    ], 'public');
}

There is a section in the Laravel documentation for this here . Laravel 文档中有一个关于的部分。

All you have to do is include your scripts like so: mix('style.css', 'vendor/your-package-name').您所要做的就是像这样包含您的脚本:mix('style.css', 'vendor/your-package-name')。

<script src="{{mix('js/main.js', 'vendor/your-package-name')}}" type="text/javascript"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM