How to Create Dummy Data in Laravel 11

How to Create Dummy Data in Laravel 11

Today, We will discuss about how to create dummy data in laravel 11. We can easily add dummy data into laravel using this factory.

In Laravel, we need test data for some functions. It takes a lot of time to add data manually. To prevent this, Laravel provides us with a factory to generate test data. The Laravel factory allows the creation of dummy or test data for testing purposes.

Now, We will create example for how to create dummy data into laravel 11. so you can follow below steps.

Now, we follow the below step for creating the Laravel 11 Yajra Datatables Example.

Overview

Step 1: Install Laravel 11
Step 2: MySQL Database Configuration
Step 3: Create Migration Table
Step 4: Create Model
Step 5: Create New Factory Class
Step 6: Add Dummy Data

Step 1 : Install Laravel 11

We are going to install laravel 11, so first open the command prompt or terminal and go to xampp htdocs folder directory using the command prompt. after then run the below command.

Step 2: MySQL Database Configuration

After complete installation of laravel. we have to database configuration. now we will open the .env file and change the database name, username, password in the .env file. See below changes in a .env file.

Step 3: Create Migration Table

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.

Step 4: Create Model

Here below command help to create the controller and model.

Student.php

Step 5: Create New Factory Class
In this step, we will create new factory class for create dummay data of students. so you can follow below command.

database\factories\StudentFactory.php
And add the below code in this file.

Step 6: Add Dummy Data
In this step, we will add dummy data into database using the below commmand.

laravel-11-dummy-data

Please follow and like us: