- Added description field to Product model and database migration. - Updated StoreProductRequest validation rules for description. - Modified product factory and seeder to include description. - Enhanced product forms and show pages to display description.
76 lines
3.3 KiB
PHP
76 lines
3.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Product;
|
|
use Domain\Models\ValueObjects\Products\BreedingMethod;
|
|
use Domain\Models\ValueObjects\Products\Business;
|
|
use Domain\Models\ValueObjects\Products\NutritionalValues;
|
|
use Domain\Models\ValueObjects\Products\ProductCategory;
|
|
use Domain\Models\ValueObjects\Products\ProductFormat;
|
|
use Domain\Models\ValueObjects\Products\Technology;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/** @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Product> */
|
|
class ProductFactory extends Factory
|
|
{
|
|
protected $model = Product::class;
|
|
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'seo_title' => $this->faker->sentence(4),
|
|
'seo_description' => $this->faker->text(150),
|
|
'picture' => $this->faker->imageUrl(800, 600, 'food'),
|
|
'picture_alt' => $this->faker->words(3, true),
|
|
'picture_title' => $this->faker->words(3, true),
|
|
|
|
'name' => ucfirst($this->faker->words(3, true)),
|
|
|
|
'category' => $this->faker->randomElement(ProductCategory::cases()),
|
|
'technology' => $this->faker->randomElement(Technology::cases()),
|
|
|
|
'breeding_methods' => $this->faker->randomElements(
|
|
BreedingMethod::cases(),
|
|
$this->faker->numberBetween(1, 3)
|
|
),
|
|
'businesses' => $this->faker->randomElements(
|
|
Business::cases(),
|
|
$this->faker->numberBetween(1, count(Business::cases()))
|
|
),
|
|
|
|
'is_egalim' => $this->faker->boolean(30),
|
|
|
|
'formats' => $this->faker->randomElements(
|
|
ProductFormat::cases(),
|
|
$this->faker->numberBetween(1, 3)
|
|
),
|
|
|
|
'description' => $this->faker->paragraph(),
|
|
'details_and_advantages' => $this->faker->paragraphs(2, true),
|
|
'handling_advices' => $this->faker->paragraph(),
|
|
'ingredients' => $this->faker->optional(0.8)->paragraph(),
|
|
|
|
'conservation_before_opening' => 'À conserver entre 0°C et 4°C.',
|
|
'conservation_after_opening' => $this->faker->optional(0.7)->sentence(),
|
|
|
|
'nutritional_values' => $this->faker->boolean(80) ? new NutritionalValues(
|
|
refWeightG: 100.0,
|
|
kj: $this->faker->randomFloat(2, 0, 3000),
|
|
kcal: $this->faker->randomFloat(2, 0, 800),
|
|
fatG: $this->faker->randomFloat(2, 0, 100),
|
|
satFatG: $this->faker->randomFloat(2, 0, 50),
|
|
carbG: $this->faker->randomFloat(2, 0, 100),
|
|
sugarG: $this->faker->randomFloat(2, 0, 100),
|
|
fiberG: $this->faker->randomFloat(2, 0, 50),
|
|
proteinG: $this->faker->randomFloat(2, 0, 100),
|
|
saltG: $this->faker->randomFloat(2, 0, 10),
|
|
) : null,
|
|
|
|
'pdf' => $this->faker->optional(0.5)->filePath(),
|
|
'inco_code' => $this->faker->optional(0.5)->bothify('INCO-####'),
|
|
];
|
|
}
|
|
}
|