33 lines
934 B
PHP
33 lines
934 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
|
|
{
|
|
$harga_per_gram = $this->faker->numberBetween(80, 120) * 10000;
|
|
$berat = $this->faker->randomFloat(2, 1, 10);
|
|
$kategoriList = Kategori::all()->pluck('id')->toArray();
|
|
return [
|
|
'nama' => $this->faker->words(3, true),
|
|
'id_kategori' => $this->faker->randomElement($kategoriList),
|
|
'berat' => $berat,
|
|
'kadar' => $this->faker->numberBetween(10, 24),
|
|
'harga_per_gram' => $harga_per_gram,
|
|
'harga_jual' => $harga_per_gram * $berat,
|
|
];
|
|
}
|
|
}
|