如何将最新的Bootstrap版本正确安装到我的Laravel 5.4 Web应用程序中?

8 php twitter-bootstrap laravel laravel-5 laravel-5.4

我是PHP的新手,而且在Laravel中我有以下问题:我必须在我的Laravel应用程序中正确安装最新的Bootstrap CSS框架版本.

进入Bootstrap下载页面:http://getbootstrap.com/getting-started/#download

它说我可以通过这个声明使用作曲家来做到这一点:

composer require twbs/bootstrap
Run Code Online (Sandbox Code Playgroud)

所以我尝试了,我在控制台中获得了这个输出:

Andrea@Andrea-PC MINGW64 /c/xampp/htdocs/HotelRegistration
$ composer require twbs/bootstrap
Using version ^3.3 for twbs/bootstrap
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing twbs/bootstrap (v3.3.7) Downloading: 100%
Package illuminate/html is abandoned, you should avoid using it. Use laravelcollective/html instead.
Writing lock file
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
Generating optimized class loader
The compiled services file has been removed.
Run Code Online (Sandbox Code Playgroud)

什么意味着以前的输出?它成功了吗?我怀疑是我找不到我的项目的.../resources/assets目录中的bootstrap.css文件 .

为什么?我错过了什么?如何将Bootstrap用于我的项目?

编辑1:我看到Composer已将BootStrap放入此文件夹:

... /供应商/拼焊板/引导/距离/ CSS/bootstrap.css

所以,遵循这个SO链接:如何通过composer下载后设置bootstrap?

我试过这样做:

php artisan asset:publish --path="vendor/twbs/dist/css" bootstrap/css
Run Code Online (Sandbox Code Playgroud)

公开vendor/twbs/dist/css的内容作为资产,但我收到此错误消息:

Andrea@Andrea-PC MINGW64 /c/xampp/htdocs/HotelRegistration
$ php artisan asset:publish --path="vendor/twbs/dist/css" bootstrap/css


  [Symfony\Component\Console\Exception\CommandNotFoundException]
  There are no commands defined in the "asset" namespace.
Run Code Online (Sandbox Code Playgroud)

所以似乎资产声明不存在.

我该怎么办?

Vai*_*ham 6

您以错误的方式导入引导程序。大多数 Laravel 使用 composer 来拉取服务器端库。Bootstrap 基本上用于前端。

Laravel 默认为您提供 Bootstrap,请参见此处

以下是对您有所帮助的步骤。

第 1 步:检查您的机器上是否安装了 Node.js 和 NPM。

node -v
npm -v
Run Code Online (Sandbox Code Playgroud)

如果未安装,请不要担心这里是链接

第 2 步:(考虑到您安装了 node.js)转到项目根文件夹并执行以下命令。

npm install
Run Code Online (Sandbox Code Playgroud)

此命令将下载所有先决条件以及您的引导程序。

第三步:编译需要的js文件。

npm run dev
Run Code Online (Sandbox Code Playgroud)

第 4 步:将 js 文件添加到您的应用程序。

<script src="/js/app.js"></script> (Or it would be already imported)
Run Code Online (Sandbox Code Playgroud)

就是这样!

你可以在这里这里找到更多

希望对你有帮助!