Category: Projects
Topic: Mini Ecommerce
Created: 3 years ago
// 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();
}