Seeding Frame Width data for miniecommerce contd...

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

// migration file 
public function up()
{
	Schema::create('frame_widths', function (Blueprint $table) {
		$table->id();
		$table->string('name');
		$table->integer('percentage');
		$table->integer('sequence');            
		$table->timestamps();
	});
}

// FrameWidthFactory.php file 
class FrameWidthFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array
     */
    private static $order = 1; 

    public function definition()
    {
        return [
            'name' => $this->faker->text(50),
            'percentage' => rand(0,15),
            'sequence' =>  self::$order++        
        ];
    }
}

// FrameWidthSeeder.php file 
public function run()
{
	//
	FrameWidth::factory(5)->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