Laravel Database Seeder using insert multiple records

Laravel Database Seeder using insert multiple records

Today, we will tell you about the Database Seeder. Laravel is a PHP framework. it provides many facilities such as Database Seeder. let’s see that taking about the laravel Database Seeder.

Database seeder means if you want to insert multiple records or some dummy data in the database it is called database seeder.

Step 1: Install Laravel and setting the database configuration.

You can follow our below article URL for this step.

Install Laravel

Step 2: Create Table using migration

Now, We need to create a migration. so we will below command using create the students table migration.

After complete migration. we need below changes in the database/migrations/create_students_table file.

Run the below command. after the changes above file.

Step3: Create the Model.

we create a student model using the below command.

Step4: Create the seeder class

we will create StudentsTableSeeder class using the below command.

Now, open the file StudentsTableSeeder.php at the database/seeds directory and replace the below content.

When we complete the changes, then we have to need to edit the database/seeds/DatabaseSeeder.php

Now, when we will execute the below command then DatabaseSeeder class is called and it will insert the records into the database.

Please follow and like us: