mirror of https://github.com/kcal-app/kcal.git
				
				
				
			
		
			
				
	
	
		
			92 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			PHP
		
	
	
	
			
		
		
	
	
			92 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			PHP
		
	
	
	
| <?php
 | |
| 
 | |
| namespace Database\Factories;
 | |
| 
 | |
| use App\Models\Food;
 | |
| use Illuminate\Database\Eloquent\Factories\Factory;
 | |
| 
 | |
| class FoodFactory extends Factory
 | |
| {
 | |
|     /**
 | |
|      * {@inheritdoc}
 | |
|      */
 | |
|     protected $model = Food::class;
 | |
| 
 | |
|     /**
 | |
|      * {@inheritdoc}
 | |
|      */
 | |
|     public function definition(): array
 | |
|     {
 | |
|         return [
 | |
|             'name' => $this->faker->word,
 | |
|             'detail' => $this->faker->optional()->sentence(2),
 | |
|             'brand' => $this->faker->optional()->word,
 | |
|             'source' => $this->faker->optional()->url,
 | |
|             'notes' => $this->faker->optional(0.25)->paragraph,
 | |
|             'serving_size' => $this->faker->randomFloat(2, 1/2, 5),
 | |
|             'serving_unit' => $this->faker->randomElement(['tsp', 'tbsp', 'cup']),
 | |
|             'serving_weight' => $this->faker->numberBetween(5, 500),
 | |
|             'serving_unit_name' => $this->faker->optional(0.25)->word,
 | |
|             'calories' => $this->faker->randomFloat(2, 0, 100),
 | |
|             'fat' => $this->faker->randomFloat(2, 0, 10),
 | |
|             'cholesterol' => $this->faker->randomFloat(2, 0, 100),
 | |
|             'sodium' => $this->faker->randomFloat(2, 0, 500),
 | |
|             'carbohydrates' => $this->faker->randomFloat(2, 0, 20),
 | |
|             'protein' => $this->faker->randomFloat(2, 0, 20),
 | |
|             'tags' => $this->faker->words,
 | |
|         ];
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Define a "tsp" serving unit.
 | |
|      */
 | |
|     public function tspServingUnit()
 | |
|     {
 | |
|         return $this->state(function (array $attributes) {
 | |
|             return [
 | |
|                 'serving_unit' => 'tsp',
 | |
|                 'serving_size' => 1,
 | |
|             ];
 | |
|         });
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Define a "tbsp" serving unit.
 | |
|      */
 | |
|     public function tbspServingUnit()
 | |
|     {
 | |
|         return $this->state(function (array $attributes) {
 | |
|             return [
 | |
|                 'serving_unit' => 'tbsp',
 | |
|                 'serving_size' => 1,
 | |
|             ];
 | |
|         });
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Define a "cup" serving unit.
 | |
|      */
 | |
|     public function cupServingUnit()
 | |
|     {
 | |
|         return $this->state(function (array $attributes) {
 | |
|             return [
 | |
|                 'serving_unit' => 'cup',
 | |
|                 'serving_size' => 1,
 | |
|             ];
 | |
|         });
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Define no serving unit.
 | |
|      */
 | |
|     public function noServingUnit()
 | |
|     {
 | |
|         return $this->state(function (array $attributes) {
 | |
|             return [
 | |
|                 'serving_unit' => null,
 | |
|                 'serving_unit_name' => 'head'
 | |
|             ];
 | |
|         });
 | |
|     }
 | |
| }
 |