49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\CredencialProfesional;
|
|
use App\Models\Persona;
|
|
use App\Models\Profesional;
|
|
use App\Models\Profesion;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Profesional>
|
|
*/
|
|
class ProfesionalFactory extends Factory
|
|
{
|
|
/**
|
|
* The name of the factory's corresponding model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $model = Profesional::class;
|
|
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'matricula' => $this->faker->unique()->numerify('#####'),
|
|
'correo' => $this->faker->unique()->safeEmail(),
|
|
'dni' => (string) $this->faker->unique()->numberBetween(20000000, 45000000),
|
|
'persona_id' => Persona::factory(),
|
|
'profesion_id' => Profesion::factory(),
|
|
'credencialprofesional_id' => CredencialProfesional::factory(),
|
|
'baja_id' => 1,
|
|
];
|
|
}
|
|
|
|
public function configure(): static
|
|
{
|
|
return $this->afterCreating(function (Profesional $profesional) {
|
|
CredencialProfesional::where('id', $profesional->credencialprofesional_id)
|
|
->update(['usuario' => $profesional->dni . '-' . $profesional->profesion_id]);
|
|
});
|
|
}
|
|
}
|