feat: Implement Warehouse and EggCollectionItem factories, updating EggCollection factory and seeder for item and warehouse management.
This commit is contained in:
parent
8813249154
commit
5c068017b2
@ -3,6 +3,7 @@
|
|||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
use App\Models\EggCollection;
|
use App\Models\EggCollection;
|
||||||
|
use App\Models\Warehouse;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,8 +19,7 @@ public function definition(): array
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'production_date' => $dateTime,
|
'production_date' => $dateTime,
|
||||||
'total_eggs' => fake()->numberBetween(500, 1500),
|
'warehouse_id' => Warehouse::first()?->id ?? Warehouse::factory(),
|
||||||
'total_broken_eggs' => fake()->numberBetween(0, 100),
|
|
||||||
'notes' => $this->faker->optional(0.4)->sentence(),
|
'notes' => $this->faker->optional(0.4)->sentence(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
28
database/factories/EggCollectionItemFactory.php
Normal file
28
database/factories/EggCollectionItemFactory.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\EggCollectionItem;
|
||||||
|
use App\Models\Unit;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\EggCollectionItem>
|
||||||
|
*/
|
||||||
|
class EggCollectionItemFactory extends Factory
|
||||||
|
{
|
||||||
|
protected $model = EggCollectionItem::class;
|
||||||
|
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
$unit = Unit::whereIn('alias', ['butir', 'kg'])->inRandomOrder()->first()
|
||||||
|
?? Unit::where('alias', 'butir')->first()
|
||||||
|
?? Unit::factory();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'unit_id' => $unit->id,
|
||||||
|
'quantity' => $unit->alias === 'butir' ? fake()->numberBetween(50, 500) : fake()->randomFloat(2, 5, 50),
|
||||||
|
'is_broken' => fake()->boolean(10), // 10% chance of being broken
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
21
database/factories/WarehouseFactory.php
Normal file
21
database/factories/WarehouseFactory.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\Warehouse;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Warehouse>
|
||||||
|
*/
|
||||||
|
class WarehouseFactory extends Factory
|
||||||
|
{
|
||||||
|
protected $model = Warehouse::class;
|
||||||
|
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => $this->faker->company().' Warehouse',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,6 +3,7 @@
|
|||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
use App\Models\EggCollection;
|
use App\Models\EggCollection;
|
||||||
|
use App\Models\EggCollectionItem;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
class EggCollectionSeeder extends Seeder
|
class EggCollectionSeeder extends Seeder
|
||||||
@ -12,6 +13,13 @@ class EggCollectionSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
EggCollection::factory()->count(30)->create();
|
EggCollection::factory()
|
||||||
|
->count(30)
|
||||||
|
->create()
|
||||||
|
->each(function ($collection) {
|
||||||
|
EggCollectionItem::factory()->count(rand(1, 3))->create([
|
||||||
|
'egg_collection_id' => $collection->id,
|
||||||
|
]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user