The Right Way to Enable Bootstrap in Laravel

Bootstrap is a free and open-source CSS framework for responsive and mobile-first front-end web development. It contains HTML, CSS, and JavaScript-based design layouts for typography, forms, buttons, route, and other interface components. This popular framework has a responsive grid system for layout, pre-built components for design patterns, and JS plugins for user interaction.

In this article, I’ll introduce you to Bootstrap, and how to install it within your Laravel 9 application.

What is Bootstrap?

Bootstrap speeds up web development and makes it easier. It’s responsive by design and compatible with a variety of browsers. It offers reliable design through reusable components, and it is exceptionally simple to use and to learn.

Bootstrap utilizes JavaScript, a built-in back for jQuery plugins, and a programmatic JavaScript API. It can be utilized with any IDE or free PHP editors, and any server-side language and technology, from ASP.NET and Ruby on Rails to PHP. The Bootstrap UI is a consistent library of designs for beautiful and intuitive web apps.

With Bootstrap, web designers can concentrate on improvements without stressing about design, to get an interactive website up and running quickly. It also offers web architects a strong establishment for making interesting Bootstrap themes.

How to Install Bootstrap 5 in Laravel 9?

Follow this step-by-step guide to use laravel bootstrap. 

1) Install Laravel Project

Execute the following command to install a new Laravel project from scratch.

composer create-project laravel/laravel –prefer-dist laravel-bootstrap

To use the newly created Laravel app:

cd laravel-bootstrap

2) Install Laravel/UI

The Laravel UI is an official library of particular or predefined UI components. It offers a login and enrollment platform for Respond, Vue, jQuery, and Bootstrap formats.

Run this command to install Laravel/UI:

composer require laravel/UI

3) Install Bootstrap in Laravel

Run this command to install the Bootstrap CSS framework in your Laravel project:

php artisan up Bootstrap

4) Install Bootstrap Auth Scaffolding

Execute the following command to install the auth scaffoldings:

php artisan up Bootstrap –auth

This concludes Bootstrap’s installation process. To make sure it’s installed properly, go to resource/js/bootstrap.js. You will see that popper.js and jQuery have been added to Bootstrap’s JavaScript file.

5) Install Bootstrap Packages

Now let’s install the Bootstrap packages for the associated frontend component.

Before moving forward, make sure you have Node installed on your local development system with the following command:

# for node

node -v

# for npm

npm -v

Finally, install the Bootstrap package and related frontend dependencies like jquery from npm with the following command:

npm install

6) Compile Assets

The resources/sass folder _variables.scss and app.scss files will be added along with sass variables and fonts.

// Fonts

@import url(‘https://fonts.googleapis.com/css?family=Nunito’);

// Variables

@import ‘variables’;

// Bootstrap

@import ‘~bootstrap/scss/bootstrap’;

Now run the command below for asset compilation.

# for development

npm run dev

Run the command below to compile CSS and JavaScript files from resources/js and resources/sass folder to the public folder.

# for production

npm run production

7) Automate SASS and JS Changes

If you don’t want to run the npm run dev command every time you make changes in SASS and JS file, use the following command.

npm run watch

This will keep an eye on your files and compile code automatically if it detects any change in SASS and JS files.

8) Using Bootstrap in Laravel Blade Template

The sass files are now compiled to a single CSS file inside the public folder. We can define the js and CSS path and use the Bootstrap js and CSS in the Laravel blade template.

<!doctype html>

<html lang=”{{ str_replace(‘_’, ‘-‘, app()->getLocale()) }}”>

<head>

    <meta charset=”utf-8″>

    <title>{{ config(‘app.name’, ‘Laravel’) }}</title>

    <!– Scripts –>

    <script src=”{{ asset(‘js/app.js’) }}” defer></script>

    <!– Styles –>

    <link href=”{{ asset(‘css/app.css’) }}” rel=”stylesheet”>

</head>

<body>

    <h1>Tutorial made by Positronx.io</h1>

</body>

</html>

Picture of Chaz Michaels

Chaz Michaels

TRENDING AROUND THE WEB

9 cities that inspired the world’s most famous novels

9 cities that inspired the world’s most famous novels

Global English Editing

Stanford researchers who tracked how people’s social circles change with age found that older adults don’t lose the ability to make friends — they simply get pickier, deliberately keeping fewer relationships that feel meaningful and letting the rest go, a shift linked to higher emotional well-being, not less

Stanford researchers who tracked how people’s social circles change with age found that older adults don’t lose the ability to make friends — they simply get pickier, deliberately keeping fewer relationships that feel meaningful and letting the rest go, a shift linked to higher emotional well-being, not less

Global English Editing

Since 2000, Northwestern Medicine has tracked 290 volunteers over age 80 using a 15-word memory test, and after 25 years the ones who still score like adults in their fifties and sixties turn out to share one habit above the rest: close, frequent contact with other people.

Since 2000, Northwestern Medicine has tracked 290 volunteers over age 80 using a 15-word memory test, and after 25 years the ones who still score like adults in their fifties and sixties turn out to share one habit above the rest: close, frequent contact with other people.

Global English Editing

The habit of stacking your own plates and wiping up your own mess before leaving a restaurant table costs nothing and asks nothing of anyone else, which is probably why it stands out so clearly to the people whose job is cleaning up after everyone who doesn’t.

The habit of stacking your own plates and wiping up your own mess before leaving a restaurant table costs nothing and asks nothing of anyone else, which is probably why it stands out so clearly to the people whose job is cleaning up after everyone who doesn’t.

Global English Editing

Harvard researchers who followed men from late adolescence into old age found that the way they learned to cope with difficult emotions mattered decades later: men who relied on less adaptive psychological defenses in midlife tended to have poorer physical health in old age

Harvard researchers who followed men from late adolescence into old age found that the way they learned to cope with difficult emotions mattered decades later: men who relied on less adaptive psychological defenses in midlife tended to have poorer physical health in old age

Global English Editing

Describing a life as busy and in demand isn’t only a complaint — consumer researchers studying status signaling found that busyness can function as a badge, because people often read a packed schedule as evidence that someone is competent, scarce, and wanted by others.

Describing a life as busy and in demand isn’t only a complaint — consumer researchers studying status signaling found that busyness can function as a badge, because people often read a packed schedule as evidence that someone is competent, scarce, and wanted by others.

Global English Editing

Subscribe to receive our latest articles!

Get updates on the latest posts and more from Small Business Bonfire straight to your inbox.