Laravel: Adding a database

We’re using Laravel in a very basic form, without any database.

Now I want to set up a database and configure Laravel to use it.

After we’ve configured the database, I’ll show you how to use forms to accept user input and store data in the database, and how to visualize this data.

I’ll also show you how you can use data from the database with dynamic routes.

The easiest way to use a database is by using SQLite.

SQLite is just a file hosted in your site, no special setup needed.

Open the .env file, and instead of the default configuration

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

add

DB_CONNECTION=sqlite

Laravel will automatically create a SQLite database in database/database.sqlite the first time you run a migration.

Lessons in this unit:

0: Introduction
1: Getting started
2: Blade
3: Dynamic routes
4: ▶︎ Adding a database
5: How to use migrations to create and modify the database schema
6: Using forms to accept user input and store it into the database
7: Adding a better layout
8: Adding the form at the bottom of the list
9: Allow users to delete dogs from the list
10: Adding authentication using Laravel Breeze
11: Only authenticated users can add items to the database
12: Push the app code to GitHub
13: Deployment
14: Dynamic routes advanced
15: Non-web routes
16: Creating commands

Join my AI Workshop!

The Web Development BOOTCAMP cohort starts in February 2026