Add forNetwork method to ServerFactory and update DatabaseSeeder to associate servers with a network
This commit is contained in:
@@ -31,6 +31,15 @@ class ServerFactory extends Factory
|
||||
];
|
||||
}
|
||||
|
||||
public function forNetwork(string $networkId): static
|
||||
{
|
||||
return $this->state(function (array $attributes) use ($networkId) {
|
||||
return [
|
||||
'external_network_id' => $networkId,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function forOrganisation(int $organisationId): static
|
||||
{
|
||||
return $this->state(function (array $attributes) use ($organisationId) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Enums\NetworkType;
|
||||
use App\Enums\OrganisationRole;
|
||||
use App\Enums\ProviderType;
|
||||
use App\Enums\RepositoryType;
|
||||
@@ -19,8 +20,6 @@ class DatabaseSeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// User::factory(10)->create();
|
||||
|
||||
$user = User::factory()->create([
|
||||
'name' => 'Harry',
|
||||
'email' => 'harry@hjb.dev',
|
||||
@@ -39,7 +38,16 @@ class DatabaseSeeder extends Seeder
|
||||
'token' => env('HETZNER_KEY'),
|
||||
]);
|
||||
|
||||
$network = $organisation->networks()->create([
|
||||
'type' => NetworkType::EXTERNAL,
|
||||
'name' => 'keystone',
|
||||
'external_id' => 'net-12345',
|
||||
'provider_id' => $provider->id,
|
||||
'ip_range' => fake()->ipv4() . '/24',
|
||||
]);
|
||||
|
||||
$servers = Server::factory(40)
|
||||
->forNetwork($network->id)
|
||||
->forOrganisation($organisation->id)
|
||||
->forProvider($provider->id)
|
||||
->create();
|
||||
|
||||
Reference in New Issue
Block a user