php-laravelHow can I use Bootstrap with Laravel in PHP?
To use Bootstrap with Laravel in PHP, you can include the Bootstrap CSS and JavaScript files into your project. You can do this by adding the following code to your <head>
tag:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
You can also use Laravel Mix, a wrapper around Webpack, to compile your Sass files into CSS and your JavaScript files into a single file. To do this, first install the laravel-mix package:
npm install laravel-mix --save-dev
Then, create a webpack.mix.js
file in the root of your project and add the following code:
const mix = require('laravel-mix');
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css');
Finally, run the following command to compile your files:
npm run dev
Parts of Code:
-
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
- This code adds the Bootstrap CSS file into your project. -
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
- This code adds the Bootstrap JavaScript file into your project. -
npm install laravel-mix --save-dev
- This command installs the laravel-mix package, which is a wrapper around Webpack. -
const mix = require('laravel-mix');
- This code adds the laravel-mix package into your project. -
mix.js('resources/js/app.js', 'public/js')
- This code compiles your JavaScript files into a single file. -
mix.sass('resources/sass/app.scss', 'public/css');
- This code compiles your Sass files into CSS. -
npm run dev
- This command compiles your files.
Helpful links
More of Php Laravel
- How do I set up a Laravel worker using PHP?
- ¿Cómo configurar PHP y Laravel desde cero?
- How do I use Laravel traits in PHP?
- How can I use React with PHP Laravel?
- How do I set the timezone in PHP Laravel?
- How do I use the GROUP BY clause in a Laravel query using PHP?
- How can I use PHP, Laravel, and Vue together to create a web application?
- How do I install Laravel using PHP?
- How can I use PHP Laravel's ZipArchive library to create a zip file?
- How can I use the @yield directive in PHP Laravel?
See more codes...