39 lines
892 B
PHP
39 lines
892 B
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\School;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Student>
|
|
*/
|
|
class StudentFactory extends Factory
|
|
{
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'school_id' => function () {
|
|
return School::factory()->create()->id;
|
|
},
|
|
'first_name' => fake()->firstName(),
|
|
'last_name' => fake()->lastName(),
|
|
'grade' => rand(7, 12),
|
|
];
|
|
}
|
|
|
|
public function forSchool(School $school)
|
|
{
|
|
return $this->state(function (array $attributes) use ($school) {
|
|
return [
|
|
'school_id' => $school->id,
|
|
];
|
|
});
|
|
}
|
|
}
|