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.
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/
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.
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.
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