Seeding Order data for miniecommerce contd...

// artisan command for migration, factory and seeder file 
php artisan make:model Order -mfs

// migration file 
public function up()
{
	Schema::create('orders', function (Blueprint $table) {
		$table->id();
		$table->string('company_name');
		$table->string('phone_number',);
		$table->string('email');
		$table->integer('job_number');
		$table->tinyInteger('status');       
		$table->timestamps();
	});
}

// OrderFactory.php file 
class OrderFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
            'company_name' => $this->faker->text(30),
            'phone_number' => $this->faker->randomNumber(),
            'email' => $this->faker->unique()->safeEmail(),
            'job_number' => $this->faker->numberBetween(1000,9000),
            'status' =>  rand(0,1)  
        ];
    }
}

// OrderSeeder.php file 
public function run()
{
	//
	Order::factory(20)->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