Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set up Bootstrap after downloading via Composer?

I'm a beginner with Composer, so I know little about it and have little experience with web application development.

I was reading the Nettuts+ Tutorial, and have a basic question about Composer.

{   "require": {     "laravel/framework": "4.0.*",     "way/generators": "dev-master",     "twitter/bootstrap": "dev-master",     "conarwelsh/mustache-l4": "dev-master"   },   "require-dev": {     "phpunit/phpunit": "3.7.*",     "mockery/mockery": "0.7.*"   },   "autoload": {     "classmap": [       "app/commands",       "app/controllers",       "app/models",       "app/database/migrations",       "app/database/seeds",       "app/tests/TestCase.php"     ]   },   "scripts": {     "post-update-cmd": "php artisan optimize"   },   "minimum-stability": "dev" } 

If I set up my composer.json file as above, after executing composer install --dev, how do I make Bootstrap available for use in the Laravel project?

I mean, I can see the Bootstrap package is downloaded to the vendor directory. Before I only used to download Bootstrap from its official website and manually put the files in the public directory of Laravel, but what is the right way to do this here? Can I leave the Bootstrap files where they are, because I want to update the Bootstrap package to its latest version periodically?

Thanks.

like image 436
Artisan Avatar asked Oct 01 '13 14:10

Artisan


People also ask

How do I link downloaded files to Bootstrap?

Another way of importing Bootstrap to HTML is to directly download the files locally to your HTML project folder. The files can be downloaded from the following links: Bootstrap 4: https://getbootstrap.com/docs/4.3/getting-started/download/ Bootstrap 5: https://v5.getbootstrap.com/docs/5.0/getting-started/download/


2 Answers

We have artisan command to publish the assets(CSS, JS,..). Something like this should work.

php artisan asset:publish --path="vendor/twitter/bootstrap/bootstrap/css" bootstrap/css php artisan asset:publish --path="vendor/twitter/bootstrap/bootstrap/js" bootstrap/js 

i am not sure about the path.. But this should work.

like image 59
brainless Avatar answered Sep 21 '22 15:09

brainless


As the tutorial says, you have to copy it to your public directory:

cp vendor/twitter/bootstrap/docs/assets/js/html5shiv.js public/js/html5shiv.js cp vendor/twitter/bootstrap/docs/assets/js/bootstrap.min.js public/js/bootstrap.min.js 

EDIT:

You really have copy them, because your assets files should lie in the public folder only and Composer is all about putting packages on your vendor's folder, which must not be visible to the outside world.

But you can create a Composer post-install-cmd:

{     "scripts": {         "post-update-cmd": "MyVendor\\MyClass::postUpdate",     } } 

And make it copy those files for you every time an update happens. It can be written using PHP, bash or any other language you can run on your host. Docs: http://getcomposer.org/doc/articles/scripts.md.

like image 44
Antonio Carlos Ribeiro Avatar answered Sep 19 '22 15:09

Antonio Carlos Ribeiro