Kasir/database/factories/ProdukFactory.php
2025-09-03 17:04:37 +07:00

37 lines
936 B
PHP

<?php
namespace Database\Factories;
use App\Models\Kategori;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Produk>
*/
class ProdukFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
$kategori = Kategori::inRandomOrder()->first();
$harga_per_gram = $this->faker->numberBetween(80, 120) * 10000;
$berat = $this->faker->randomFloat(2, 1, 10);
return [
'nama' => $kategori->nama . ' ' . $this->faker->words(mt_rand(1, 2), true),
'id_kategori' => $kategori->id,
'berat' => $berat,
'kadar' => $this->faker->numberBetween(10, 24),
'harga_per_gram' => $harga_per_gram,
'harga_jual' => $harga_per_gram * $berat,
];
}
}