Let's check the demo of how to add dummy data in category table using Laravel seeder.
First, you need to install faker into Laravel. Faker is a PHP library that generates fake data for you
Install faker using composer command
composer require fzaninotto/faker
After installing faker you can see in require dev parameter in composer.json file in Laravel as below
composer.json file has below configuration:
"require-dev": {
"fzaninotto/faker": "~1.4",
},
namespace App; use Illuminate\Database\Eloquent\Model; class Category extends Model { public $timestamps=false; }
1,category1, et sit et mollitia sed.
2,category2, et sit et mollitia sed.
etc into categories table.
use Carbon\Carbon; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; class CategoriesTableSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public function run() { // DB::table('categories')->delete(); $faker = Faker\Factory::create(); for ($i = 1; $i < 20; $i++) { DB::table('categories')->insert([ 'CategoryName' => 'Category'.$i,'Description'=> $faker->text ]); } } }For the run, this CategoriesTableSeeder add this call into DatabaseSeeder class.
use Illuminate\Database\Seeder; class DatabaseSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public function run() { // $this->call(UsersTableSeeder::class); $this->call(CategoriesTableSeeder::class); } }