Seeding user data for miniecommerce

Step 01: Creating fresh laravel project

composer create-project laravel/laravel miniecommerce

Step 02: Setting Up migration, factory and seeder of User model

// migration file
public function up()
{
	Schema::create('users', function (Blueprint $table) {
		$table->id();
		$table->integer('role_id');
		$table->string('name');
		$table->string('email')->unique();
		$table->timestamp('email_verified_at')->nullable();
		$table->string('password');
		$table->rememberToken();
		$table->timestamps();
	});
}

// UserFactory.php file
public function definition()
{
	return [
		'name' => $this->faker->name(),
		'role_id' => rand(1,2),
		'email' => $this->faker->unique()->safeEmail(),
		'email_verified_at' => now(),
		'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
		'remember_token' => Str::random(10),
	];
}

// artisan command 
php artisan make:seeder UserSeeder

// UserSeeder.php file
public function run()
{
   //
   User::factory(2)->create();
}

Related Posts


Building mini ecommerce in Laravel

Listing rows of users - crud

Adding user data - crud of users

Editing user data - crud of users

Deleting user data - crud of users

Listing rows of products - crud

Listing rows of profiles - crud

Listing rows of orders - crud

Listing rows of order items - crud