This commit is contained in:
Bozhidar 2024-05-13 11:55:08 +03:00
parent cacaa5c452
commit 08d3a9729c
3 changed files with 32 additions and 2 deletions

View file

@ -25,7 +25,12 @@ class MinecraftServerResource extends Resource
{
return $form
->schema([
//
Forms\Components\TextInput::make('name')
->label('Name')
->placeholder('Enter the name of the server'),
]);
}

View file

@ -14,7 +14,9 @@ class MinecraftServer extends Model
/**
* The attributes that are mass assignable.
*/
protected $fillable = [];
protected $fillable = [
'name',
];
protected static function booted(): void
@ -33,6 +35,27 @@ class MinecraftServer extends Model
static::creating(function ($model) {
$minectaftId = 1;
$findLastMinecraftServer = MinecraftServer::orderBy('id', 'desc')->first();
if ($findLastMinecraftServer) {
$minectaftId = $findLastMinecraftServer->id + 1;
$model->name = 'Server #'.$minectaftId;
} else {
$model->name = 'Server #1';
}
$minecraftServersPath = '/home/minecraft/servers';
$minecraftServerPath = $minecraftServersPath . '/'.$minectaftId;
shell_exec('mkdir -p '.$minecraftServerPath);
$minecraftServerDocker = view('minecraft::actions.docker-compose', [
'id' => $minectaftId
])->render();
file_put_contents($minecraftServerPath.'/docker-compose.yml', $minecraftServerDocker);
$docker = shell_exec('cd '.$minecraftServerPath.' && docker-compose up -d');
dd($docker);
});

View file

@ -7,3 +7,5 @@ services:
- "25565:25565"
environment:
EULA: "TRUE"
GAMEMODE: survival
DIFFICULTY: normal