This article mainly introduces the complete solution of Laravel integrating Bootstrap 4. It is very good and has reference value. Friends in need can refer to it
[Related video recommendations: Bootstrap tutorial 】
If you want to use bootstrap 4 directly on laravel5.5, this should be relatively wise, because the final version of bootstrap 4 has been released, so here is good news, That is, you don’t need to follow the steps below step by step. You can quickly use boostrap 4 by installing a plug-in. The plug-in link: laravelnews/laravel-twbs4. I won’t go into details on how to use it. Just follow the plug-in documentation. . If you are integrating bootstrap 4 in a version before laravel5.5, then you still need to go through the following process:
(1) Install bootstrap and corresponding dependencies
npm install bootstrap@4.0.0-beta popper.js --save-dev
Replace bootstrap -sass Delete from package.json, and then execute npm install
(2) Introduce new bootstrap into your app.scss file sass file
//替换掉之前bootstrap-sass的引入 //如果你是laravel 5.5及以后的版本,这里的node_modules换成~符号 @import "node_modules/bootstrap/scss/bootstrap";
(3) Compile bootstrap js file
In this step you may want to directly copy a copy of your bootstrap.min.js file to public directory, and then reference it, but in fact this is not possible because the js component of bootstrap 4 also relies on jquery and Popper.js , and the default bootstrap.min.js file does not Compile it in.
Method 1 uses bootstrap.min.js to compile
At this time we need to add these lines to webpack.mix.js:
mix.autoload({ jquery: ['$', 'window.jQuery',"jQuery","window.$","jquery","window.jquery"], 'popper.js/dist/umd/popper.js': ['Popper'] }); mix.js([ 'node_modules/bootstrap/dist/js/bootstrap.min.js' ],'public/js/bootstrap.min.js')
You can see that we automatically load jquery and Popper.js through the mix.autoload() method, so that the mix.js below () method compiles the corresponding dependencies when compiling the bootstrap.min.js file. Finally, we send the compiled file to the public/js/ directory, and then call it where needed. Can.
Method 2 uses bootstrap.bundle.min.js to compile
If you go to bootstrap’s node_modules/bootstrap/dist/ In the js/ directory, you will find another bootstrap.bundle.min.js file. Popper.js has actually been pre-compiled in this file, but there is no jquery, so in the webpack.mix.js file just now, We can actually write it like this:
mix.autoload({ jquery: ['$', 'window.jQuery',"jQuery","window.$","jquery","window.jquery"] }); mix.js([ 'node_modules/bootstrap/dist/js/bootstrap.bundle.min.js' ],'public/js/bootstrap.min.js')
The final compressed files are the same. If you use npm run dev to compile, then the files compressed by the second method will be smaller, but if When it comes to the production environment, that is, npm run production , then the sizes of both are the same.
Of course, in addition to writing one less line, the second method also has another advantage, that is, at the beginning, there is no need to npm install popper.js . There is nothing wrong with it. Download less. Just a component.
(4) Load the pagination blade of bootstrap 4
At this point, you can actually use it in the blade view according to the bootstrap 4 document, or use the existing bootstrap 3 Changing it to 4 is because this is a relatively disruptive upgrade of bootstrap, so it is not backward compatible. It depends on the size of your project, but generally speaking, changing bootstrap 3 to 4 will take a while.
I won’t go into details. What you may be confused about during this period is how to upgrade the paging style of bootstrap 4. There are many methods. Here is the simplest and fastest one:
First of all, find you The resources/views/vendor/pagination
directory, this is laravel’s default paging style view file. If you don’t execute php artisan vendor:publish
, you will have it
default.blade.php bootstrap-4.blade.php simple-default.blade.php simple-bootstrap-4.blade.php
You can see that laravel has actually prepared the bootstrap 4 paging template file for us by default. The simplest thing at this time is to change the file name. The previous default.blade is the original bootstrap 3 , so we can change it to bootstrap-3.blade.php , and then change bootstrap-4.blade to the default default.blade , so that when laravel loads paging The style used is 4.
Of course, you can also specify a specific paging view file every time you render a paging, as the laravel documentation says, such as:
$paginator->links('vendor.pagination.bootstrap-4')
But this is too troublesome, just know it.
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Explain in detail the issue of implementing react server rendering
How to write a PC-side carousel chart using jquery (details Tutorial)
How to develop through the header component in Vue (detailed tutorial)
The above is the detailed content of How to integrate Bootstrap 4 in Laravel?. For more information, please follow other related articles on the PHP Chinese website!

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools
