48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Country;
|
|
use App\Models\Supplier;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends Factory<Supplier>
|
|
*/
|
|
class SupplierFactory extends Factory
|
|
{
|
|
protected $model = Supplier::class;
|
|
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'name' => $this->faker->company(),
|
|
'url' => $this->faker->optional()->url(),
|
|
'contact_person' => $this->faker->optional()->name(),
|
|
'email' => $this->faker->optional()->companyEmail(),
|
|
'phone' => $this->faker->optional()->phoneNumber(),
|
|
'country_id' => Country::query()->value('id') ?? $this->resolveCountryId(),
|
|
'notes' => null,
|
|
'active' => true,
|
|
];
|
|
}
|
|
|
|
protected function resolveCountryId(): int
|
|
{
|
|
$country = Country::query()->firstOrCreate(
|
|
['code' => 'TE'],
|
|
[
|
|
'phone' => '00',
|
|
'en' => 'Testland',
|
|
'de' => 'Testland',
|
|
'es' => 'Testland',
|
|
'fr' => 'Testland',
|
|
'it' => 'Testland',
|
|
'ru' => 'Testland',
|
|
'active' => true,
|
|
]
|
|
);
|
|
|
|
return (int) $country->id;
|
|
}
|
|
}
|