add forSchool method to UserFactory

This commit is contained in:
Matt Young 2025-07-05 21:57:43 -05:00
parent bb4785fdbf
commit d21e568d60
1 changed files with 11 additions and 0 deletions

View File

@ -2,6 +2,7 @@
namespace Database\Factories;
use App\Models\School;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
@ -38,6 +39,7 @@ class UserFactory extends Factory
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
'school_id' => null,
];
}
@ -64,4 +66,13 @@ class UserFactory extends Factory
'is_tab' => 1,
]);
}
public function forSchool(School $school)
{
return $this->state(function (array $attributes) use ($school) {
return [
'school_id' => $school->id,
];
});
}
}