- menyesuaikan model jika ada yang salah seperti kurangnya trait SoftDeletes, casting yang salah, relasi yang kurang dan lainnya - memperbaiki enum di migrasi
30 lines
759 B
PHP
30 lines
759 B
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Purchase;
|
|
use App\Models\PurchaseItem;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
class PurchaseItemFactory extends Factory
|
|
{
|
|
protected $model = PurchaseItem::class;
|
|
|
|
public function definition(): array
|
|
{
|
|
$unitPrice = $this->faker->numberBetween(10000, 100000);
|
|
$quantity = $this->faker->numberBetween(1, 10);
|
|
|
|
return [
|
|
'purchase_id' => Purchase::factory(),
|
|
'user_id' => User::factory(),
|
|
'purchasable_type' => null,
|
|
'purchasable_id' => null,
|
|
'quantity' => $quantity,
|
|
'unit_price' => $unitPrice,
|
|
'total_price' => $unitPrice * $quantity,
|
|
];
|
|
}
|
|
}
|