How do I create a Database table in Laravel PHP?

Published January 17, 2022

In this post, we'll show you how to connect your Laravel app to a MySQL database, make database tables, and add some sample data.

Follow these simple steps in Laravel to build a database table:

Step1: Using your composer command prompt, create a new Laravel project  using the following command

 composer create-project --prefer-dist laravel/laravel dbmeza

Laravel8 create table

A new directory dbtable is created a new Laravel is installed


Laravel8 create table 2

Step 2: First, we must create a new database in which we will create Laravel tables. Create a new database called "Lalaveltables" in PHPmyAdmin

Laravel8 create table 3

Step 3: Now connect your Laravel application with the database. To establish a connection, open your .env file and configure your DB_CONNECTION, DB_Host, DB_PORT, DB_DATABASE, DB_USERNAME, and DB_PASSWORD

Laravel8 create table 4

We have successfully connected our database to our web application

Step 4: Now, in the composer command prompt, run the command

composer require laravel/jetstream


Laravel8 create table 5

Step 5: using the command php artisan Jetstream: install livewire, Install livewire

Laravel8 create table 6

Step 6: Now, we need to run  the npm install and npm run dev

npm install

Laravel8 create table 7


npm run dev

Laravel8 create table 8


Step 7:  Run the php artisan migrate. To create the new tables in the database and insert sample data.

Laravel8 create table 9


That’s it. New tables have been created in the database, and sample data inserted

Laravel8 create table 10



Download Source code


Article Contributed By :