Easy Ways to Install and Use SQLite in Laravel

Easy Ways to Install and Use SQLite in Laravel
Hello everyone, welcome back at porkaone. This time I will share a tutorial on how to use SQLite in Laravel. How?, let's follow the discussion below.



Laravel is made very powerful, Laravel has provided various kinds of DBMS drivers to facilitate application development. Among the drivers provided are MySQL, PostgreSQL, and SQLite. And of the three, SQLite is the simplest and light enough to use. Maybe you are used to using SQLite for your mobile app needs, but actually SQLite can also be used for web-based applications.

SQLite has several advantages, like: no need to install a separate DBMS such as MySQL or PostgresSQL. In this way, the saved data is automatically stored in our Laravel application directory. SQLite is also very light, easy to use, and simple.

SQLite is usually used for demo applications, or test applications. In addition, because SQLite is based on the SQL language, almost all commands and their syntax are not much different, and of course you don't need to adapt anymore. You can also use SQLite for lightweight applications such as to-do-lists. Or a less complex data library application.



Install SQLite on Local Computer

To install SQLite on ubuntu please run the command below.

sudo apt install sqlite3 php-sqlite3

And if you are a windows user, then you don't need to install SQLite on your respective windows operating system.



How to Use SQLite in Laravel

1. I assume you all have downloaded the laravel project. So I don't need to explain the installation steps anymore.

2. Open the database folder and create a new file with the name database.sqlite. Or you can run the command below to create the file. We don't need to fill it, because the contents will be migrated later.

touch database/database.sqlite


3. Open the .env file. Then change the database settings like the script below. Here we change the connection driver and delete the database name.

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_USERNAME=root
DB_PASSWORD=


4. After making the changes, don't forget to run the command below. The command below serves to make the database settings to the latest.

php artisan config:cache



5. Ok, SQLite database settings are complete. How easy is it? Now then you just run the command below, to create some new tables in the database.sqlite file

php artisan migrate

If the output is like the image below, it means that you have successfully connected the SQLite database.

Laravel migrate
Table Migration



How to View SQLlite Views in VsCode

To see the table, its structure, and the contents in the table, we can use an extension called SQLite Viewer in visual studio code. Please install first. Then if you have, just open the database.sql file that you created earlier. So it looks like this.

SQLite Viewer Extension
SQLite View



Ok, so this tutorial, about how to install and use SQLite in laravel. May be useful. If there is anything that needs to be asked, please ask directly in the comments column below or you can ask directly on the sahretech fanspage. Bye and see you.

Post a Comment

0 Comments