Files
pterodactyl-panel/database/Factories/AllocationFactory.php
T

59 lines
1.3 KiB
PHP
Raw Normal View History

2021-01-23 12:09:16 -08:00
<?php
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
2021-01-23 12:09:16 -08:00
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Models\Allocation;
use Pterodactyl\Models\Node;
use Pterodactyl\Models\Server;
2021-01-23 12:09:16 -08:00
2026-10-05 18:10:18 -04:00
/**
* @extends Factory<Allocation>
*/
2021-01-23 12:09:16 -08:00
class AllocationFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Allocation::class;
/**
* Define the model's default state.
*/
public function definition(): array
{
return [
2026-10-05 18:10:18 -04:00
'node_id' => Node::factory()->withLocation(),
'ip' => fake()->unique()->ipv4(),
'port' => fake()->unique()->numberBetween(1024, 65535),
2021-01-23 12:09:16 -08:00
];
}
/**
* Attaches the allocation to a specific server model.
*/
public function forServer(Server $server): self
{
return $this->for($server)->for($server->node);
}
2026-10-05 18:10:18 -04:00
/**
* Attaches the allocation to a freshly created server on the same node.
*/
public function withServer(): self
{
return $this->state(function (): array {
$server = Server::factory()->withRelationships()->create();
return [
'node_id' => $server->node_id,
'server_id' => $server->id,
];
});
}
2021-01-23 12:09:16 -08:00
}