added plan factory and seeder

This commit is contained in:
2023-12-06 12:21:14 +03:00
parent 966f7a3e79
commit a975c75bfd
2 changed files with 70 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
<?php
namespace Database\Factories;
use FakerRestaurant\Provider\en_US\Restaurant;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Plan>
*/
class PlanFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
$faker = \Faker\Factory::create();
$this->faker->addProvider(new Restaurant($faker));
$typeBody = [
'fit' => $this->faker->boolean(),
'slim' => $this->faker->boolean(),
'behavior' => $this->faker->boolean(),
'wellness' => $this->faker->boolean(),
];
$packetsOptions = [
'items' => [$this->faker->fruitName(), $this->faker->meatName(), $this->faker->sauceName()],
'price' => $this->faker->randomNumber(),
'short' => $this->faker->foodName(),
'description' => $this->faker->text(),
];
return [
'name' => $this->faker->foodName(),
// 'image' => $this->faker->image('application/storage/fake_images', 640, 480, null, false),
'image' => storage_path('public/img/Photo_C.png'),
'duration' => $this->faker->randomElement([7, 14,21]),
'state' => $this->faker->randomElement(['active', 'draft', 'archived']),
'type' => $typeBody,
'details' => $this->faker->text(),
'packets_count' => $this->faker->randomElement([1, 3]),
'packet1_options' => $packetsOptions,
'packet2_options' => $packetsOptions,
'packet3_options' => $packetsOptions,
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Database\Seeders;
use Illuminate\Support\Facades\Storage;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\Plan;
class PlanTablesSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
Plan::factory()->count(10)->create();
}
}