Laravel dummy data input

This tutorial is supported on Laravel-5.4 or lower version.
To store dummy data into posts table having a Post model, we need to work with:
  1. Factory
  2. Seeder
Configure factory:
  1. Create factory with the command:
    php artisan make:factory PostFactory --model=Post
  2. Open the factory and write the follwing code inside r[...]
    'title'=>$faker->sentence(),
    'content'=>$faker->paragraphs(rand(2, 10), true),
Now configure seeder:
Edit run() function inside seeder as like below:
public function run() {
     factory('App\Post', 10)->create();
}
Instead of editing seeder, you can work on tinker as like:
php artisan tinker
factory('App\Post', 10)->create()
Source: https://www.youtube.com/watch?v=6amfO-ysCME

Labels: ,

© copyright-2020 Rejaul