Laravel is a web framework that runs on PHP and is used to create custom applications. Also, it is an open-source free framework. Laravel handles all the things that are annoying to do manually. It handles things such as Authentication, routing, and HTML templates. Since it runs on PHP, Laravel is a server-side framework.
Laravel features a tool that allows developers to store dummy data in the database. The process of including this dummy data is called seeding. You can add data for testing to the database table using the seeder. This is a handy feature for testing. Because it helps developers optimize performance and detect bugs.
You can generate a seeder by executing the following Artisan command.
php artisan make:seeder UserSeeder
All the seeders that will be generated will be placed in a directory called database/seeders. A seeder class features one method by default: run. Once the db:seed command is executed, then the default method is called automatically.
You can start by seeding your database using the db:seed command. But, this command runs Database/Seeders/DatabaseSeeder class by default. This will, in turn, invoke all other seed classes. To do it right use, you need to specify a specific seeder using a --class option to run independently.
php artisan db:seed
php artisan db:seed --class=UserSeeder
Or, you can combine migrate:fresh command and --seed option to seed your database. This command drops all the tables then re-runs the migrations only.
Not all seeding operations are safe; some may cause you to alter or lose data. The production environment has been configured to prevent this from happening. It does this by promoting a confirmation before execution.
Contact us, if you did not find the right answer or you have a other question?
All rights reserved. Please consider the information, scripts and instructions carefully before using it yourself. Make sure you have ample backups! The information, scripts and instructions are provided without warranty. Consult a professional if you are unsure. Anto does not speak on behalf of any company and our opinions are our own.