twitter-bootstrap Laravel 5 发布资产

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29443735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 22:30:27  来源:igfitidea点击:

Laravel 5 Publishing Assets

phptwitter-bootstraplaravel-5

提问by toni rmc

I'm using Laravel 5 and I want to publish twitter bootstrap CSS and JS to public directory. I did used Composer to get twitter/bootstrap package and that part went OK, so files I want are now in vendor/twitter/bootstrap/dist

我正在使用 Laravel 5,我想将 twitter bootstrap CSS 和 JS 发布到公共目录。我确实使用 Composer 来获取 twitter/bootstrap 包,那部分运行正常,所以我想要的文件现在在vendor/twitter/bootstrap/dist

But I can't get it to work. I get 'Nothing to publish.' message every time I try.
Here are the steps I took:

但我无法让它工作。我得到“没什么可发布的”。每次尝试时都会留言。
以下是我采取的步骤:

  • use artisan to generate class: php artisan make:provider BootstrapServiceProvider

  • edit the boot()method in that class

  • register service provider in config/app.php
    providers => [ ...
    'App\Providers\BootstrapServiceProvider',
    ],

  • 使用 artisan 生成类: php artisan make:provider BootstrapServiceProvider

  • 编辑boot()该类中的方法

  • 在 config/app.php 中注册服务提供者
    providers => [ ...
    'App\Providers\BootstrapServiceProvider',
    ],

Bellow is my generated file with the class and it's edited boot()method.

Bellow 是我生成的带有该类的文件,它是经过编辑的boot()方法。

BootstrapServiceProvider.php

BootstrapServiceProvider.php

<?php namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class BootstrapServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     * Move twitter bootstrap CSS and JS into public directory
     *
     * @return void
     */
    public function boot()
    {
        $this->publishes([
                     __DIR__ . 'vendor/twitter/bootstrap/dist' => public_path('vendor/bootstrap'),
        ], 'public');
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

}

I have tried:

我努力了:

php artisan vendor:publish --tag=public
php artisan vendor:publish --tag=public --force
php artisan vendor:publish
php artisan vendor:publish --force

And also tried with removed second 'public'parameter from boot() method.

并尝试'public'从 boot() 方法中删除第二个参数。

Every time I get Nothing to publish..

每次我什么都没有发布。.

boot() method doesn't even get called. What do I have to do to get it to working?
Maybe put something in the register()method? Right now is just empty.
Or some other step?

boot() 方法甚至不会被调用。我该怎么做才能让它工作?
也许在register()方法中放一些东西?现在只是空的。
还是别的什么步骤?

采纳答案by toni rmc

To answer my own question.

回答我自己的问题。

After reinstalling Laravel from 5.0.26 to 5.0.25 everything worked.
Even after updating it again to 5.0.26 and higher it still works.

将 Laravel 从 5.0.26 重新安装到 5.0.25 后,一切正常。
即使再次将其更新到 5.0.26 及更高版本,它仍然有效。

I don't know why it didn't work before composer update.

我不知道为什么在作曲家更新之前它不起作用。

Everything else is the same as above except boot()method has to be fixed to point to the right vendor path when calling publishes().

其他一切都与上面相同,除了boot()方法必须在调用publishes().

Fixed version of boot():

固定版本boot()

public function boot()
{
    $this->publishes([
        __DIR__ . '/../../vendor/twitter/bootstrap/dist' => public_path('vendor/bootstrap'),
    ], 'public');
}

To automate it all add this entries in composer.json in scripts:section under "post-install-cmd"and "post-update-cmd":

要自动执行所有操作,请在 composer.json 的“post-install-cmd”“post-update-cmd”scripts:部分下添加这些条目:

"scripts": {
    "post-install-cmd": [
          "...",
          "php artisan vendor:publish --tag=public --force"
    ],
    "post-update-cmd": [
          "...",
          "php artisan vendor:publish --tag=public --force"
    ],
},

回答by ceekays

How to install Bootstrap in Laravel using composer

如何使用 composer 在 Laravel 中安装 Bootstrap

Although it has been a year since this question was posted, I believe my response is going to help someone out there. This works perfectly for me.

虽然这个问题发布已经一年了,但我相信我的回答会帮助那里的人。这对我来说非常有效。

I am using Laravel Framework version 5.2.31 (do php artisan --versionto check your Laravel version). Follow the steps below:

我正在使用 Laravel Framework 版本 5.2.31(php artisan --version检查您的 Laravel 版本)。请按照以下步骤操作:

  1. Open the terminal and run composer require twbs/bootstrap 3.3.6. If you want a different version from 3.3.6, check the latest distribution version on https://packagist.org/packages/twbs/bootstrap.
  2. Create a Bootstrap service provider class using artisan command: php artisan make:provider BootstrapServiceProvider
  3. Open your Bootstrap service provider class in app/Providers/BootstrapServiceProvider.php. Edit the boot()method as follows:

    public function boot() { $this->publishes([base_path('vendor/twbs/bootstrap/dist') => public_path('vendor/bootstrap')],'public'); }

    The code above will instruct artisanto copy directory vendor/twbs/bootstrap/distto public/vendor/bootstrap.

  4. register service provider in config/app.php by adding DealerPortal\Providers\BootstrapServiceProvider::class,below the list of Application Service Providers

  5. Run vendor:publish --tag=public --forceto complete this task.

  1. 打开终端并运行composer require twbs/bootstrap 3.3.6。如果您想要与 3.3.6 不同的版本,请查看https://packagist.org/packages/twbs/bootstrap上的最新分发版本。
  2. 使用 artisan 命令创建一个 Bootstrap 服务提供者类: php artisan make:provider BootstrapServiceProvider
  3. app/Providers/BootstrapServiceProvider.php. 编辑boot()方法如下:

    public function boot() { $this->publishes([base_path('vendor/twbs/bootstrap/dist') => public_path('vendor/bootstrap')],'public'); }

    上面的代码将指示artisan将目录复制vendor/twbs/bootstrap/distpublic/vendor/bootstrap.

  4. 在 config/app.php 中注册服务提供者,在Application Service ProvidersDealerPortal\Providers\BootstrapServiceProvider::class,列表下方添加

  5. 运行vendor:publish --tag=public --force以完成此任务。

Bonus step:

奖励步骤:

If you want to automate the process of publishing Bootstrap all add php artisan vendor:publish --tag=public --forceto post-install-cmdand post-update-cmdsection of your composer.jsonfile.

如果你想自动发布引导所有附加的过程php artisan vendor:publish --tag=public --forcepost-install-cmdpost-update-cmd你的部分composer.json文件。

回答by Gadi

Setting the path below worked for me: (thanks for the rest of the answer)

设置下面的路径对我有用:(感谢其余的答案)

public function boot()
{
    $this->publishes([
    vendor/twitter/bootstrap/dist' => public_path('vendor/bootstrap'),
    ], 'public');
}

回答by Frederiek

This also may be caused by config cache. if you get this kinda error , use php artisan config:clear

这也可能是由配置缓存引起的。如果出现这种错误,请使用 php artisan config:clear

and retry php artisan vendor:publish

并重试 php artisan vendor:publish