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
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.phpproviders => [
...
'App\Providers\BootstrapServiceProvider',
],
Bellow is my generated file with the class and it's edited boot()
method.
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.
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?
To submit a package to Packagist, first create an account open in new window and then use the Submit link open in new window and specify the public repository URL to the git repository of your package. Packagist will now host a so-called dev-master version of your package.
The vendor:publish command is used to publish any assets that are available from third-party vendor packages. It provides a few options to help specifically choose which assets should be published. The following table lists and describes each of the options that are available for use: Option. Description.
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.
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()
.
Fixed version of 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":
"scripts": {
"post-install-cmd": [
"...",
"php artisan vendor:publish --tag=public --force"
],
"post-update-cmd": [
"...",
"php artisan vendor:publish --tag=public --force"
],
},
How to install Bootstrap in Laravel using composer
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 --version
to check your Laravel version). Follow the steps below:
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.php artisan make:provider BootstrapServiceProvider
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 artisan
to copy directory vendor/twbs/bootstrap/dist
to public/vendor/bootstrap
.
register service provider in config/app.php by adding DealerPortal\Providers\BootstrapServiceProvider::class,
below the list of Application Service Providers
Run vendor:publish --tag=public --force
to complete this task.
Bonus step:
If you want to automate the process of publishing Bootstrap all add php artisan vendor:publish --tag=public --force
to post-install-cmd
and post-update-cmd
section of your composer.json
file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With