Web Prepration

Web Concept Tutorials

Angular, Laravel

In this post, I will explain “How to create database seeder in Laraver” for insert data in the database. Laravel provides the facility to seed your database with dummy data using Laravel Seeder Class. By default, all seeds files are stored at the database/seeds directory.

What is Database Seeder in Laravel?

Database seeds extremely useful because testing with various data allows you to likely detect bugs. Database seeder in Laravel is the most useful feature, We have to simply make a one-time seeder with some dummy data, that way we can simply reuse when you deploy project first time. We can make seeders after the migration of the table.

How to run seeder in Laravel?

Laravel by default provides DatabaseSeeder class to execute database related operations. Any operation will execute through call() method of Seed class.

So in this example, we will add some dummy data of the user’s table from scratch. Laravel provides commands for creating seeds and run.

How To Create a Seeder Class in Laravel?

For generating seeder Class we need to run given below make: seeder command.

After running the above command successfully, a new file created in the seeds folder “UsersTableDataSeeder”. In this file, I make 10 records in users table using insert query. So just open created file “UsersTableDataSeeder” and copy below code and paste it.

I hope you might have understood it properly, keep reading our other blogs posts for more coding tricks.


0 comment on How To Create Database Seeder In Laravel

Write a comment

Your email address will not be published. Required fields are marked *