Seeding profile data for miniecommerce contd...

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

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

// ProfileFactory.php file 
namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;

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

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

// ProfileSeeder.php file 
namespace Database\Seeders;

use App\Models\Profile;
use Illuminate\Database\Seeder;

class ProfileSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //
        Profile::factory(10)->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