LARAVEL 8 – Bootstrap 5 – Datatables

1. LARAVEL 8 - Bootstrap 5 - DataTables - Introduction

Let me introduce a demo Laravel 8Bootstrap 5 project featuring Datatables.

You can quickly adapt this project to your own needs.

Tip :

If you’re looking for an excellent Local Web Development Server to develop your PHP based applications in a Microsoft Windows environment, please read my posts regarding Laragon.

2. LARAVEL 8 - Bootstrap 5 - DataTables - Description

This application is PHP 8 compatible and build using : Features :
  • Top button bar to quickly navigate to the main parts of your application
  • Offcanvas menu to access less frequently used parts
  • Datatables, fully integrated with build in :
    • Create – Show – Update – Delete (CRUD) with Bootbox.js dialogs and Toastr notifications
    • Copy to clipboard
    • Export to PDF and Excel
    • Print function
    • Items per page selector
    • Column visibility selector
    • Search with result highlighting
    • Server-side pagination and filtering
    • Multiple row selection (for mass deletes)
    • Inline boolean field toggable
    • Help
Special feature : The top menu contains in its center a dropdown selector for the year. This is implemented as a global session variable [APP].[YEAR] and allows you to easely filter datatable datasets (when needed) to reflect the data concerning the selected year. This is extreem helpfull if you manage models that depend on the year, like for instance deliveries, orders, productions, and so on… In this demo project, 2 models are already implemented :
  • Customers, available to all logged in users
  • Users, only available to logged in users with the property Developer
Use their controller and the corresponding views as a base to create new datatables utilising your own project models.

Tip:

This demo Laravel 8 – Bootstrap 5 project using Datatables is available on GitHub.

Open source under MIT License.

2. LARAVEL 8 - Bootstrap 5 - DataTables - Build

a. Clone the GitHub repository

Inside the root folder of your local web development environment, open a new terminal window. Enter the command :
git clone https://github.com/MGeurts/laravel-8-bootstrap-5-datatables.git
Change directory into the newly created project folder.

b. Install Composer Dependencies

Enter the command : 

composer install

c. Install NPM Dependencies

Enter the commands : 

npm install
npm run dev

d. Create your copy of the .env file

Enter the command :

cp .env.example .env

e. Generate an App Encryption Key

Enter the command :
php artisan key:generate

f. Create an empty database for our application

Use your favorite database management tool to create an empty database.
Configure a username and password.

g. Configure the .env file

Open the .env file for editing :
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=********
Adjust the DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME and DB_PASSWORD options to match your situation. Also adjust the mail settings:
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
Adjust the MAIL_HOST, MAIL_PORT, MAIL_USERNAME, MAIL_PASSWORD, MAIL_ENCRYPTION and MAIL_FROM_ADDRESS options to match your situation.

h. Migrate the database

Enter the command : :
php artisan migrate

i. Open the application

You now have a working Laravel 8 – Bootstrap 5 application using Datatables.

Open a browser and go to the url of your application.

In the header button bar, on the right-hand side, click the green Login button to login.

E-mail : admin@admin.com
Password : password

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.