Add mount_server table, fix wrong field type on other many to many tables, add routes for mounting and unmounting mounts on a server, finish server admin mounts page

This commit is contained in:
Matthew Penner 2020-05-21 14:23:12 -06:00
parent a0900b8b94
commit 0eb29dac9c
8 changed files with 119 additions and 22 deletions

View file

@ -178,6 +178,8 @@ class ServerViewController extends Controller
*/
public function mounts(Request $request, Server $server)
{
$server->load('mounts');
return $this->view->make('admin.servers.view.mounts', [
'mounts' => $this->mountRepository->getMountListForServer($server),
'server' => $server,

View file

@ -378,4 +378,34 @@ class ServersController extends Controller
return response('', 204);
}
/**
* Add a mount to a server.
*
* @param Server $server
* @param int $mount_id
* @return \Illuminate\Http\RedirectResponse
*/
public function addMount(Server $server, int $mount_id)
{
$server->mounts()->attach($mount_id);
$this->alert->success('Mount was added successfully.')->flash();
return redirect()->route('admin.servers.view.mounts', $server->id);
}
/**
* Remove a mount from a server.
*
* @param Server $server
* @param int $mount_id
* @return \Illuminate\Http\RedirectResponse
*/
public function deleteMount(Server $server, int $mount_id)
{
$server->mounts()->detach($mount_id);
$this->alert->success('Mount was removed successfully.')->flash();
return redirect()->route('admin.servers.view.mounts', $server->id);
}
}

View file

@ -12,8 +12,9 @@ namespace Pterodactyl\Models;
* @property bool $read_only
* @property bool $user_mountable
*
* @property \Illuminate\Database\Eloquent\Relations\BelongsToMany $eggs
* @property \Illuminate\Database\Eloquent\Relations\BelongsToMany $nodes
* @property \Pterodactyl\Models\Egg[]|\Illuminate\Database\Eloquent\Collection $eggs
* @property \Pterodactyl\Models\Node[]|\Illuminate\Database\Eloquent\Collection $nodes
* @property \Pterodactyl\Models\Server[]|\Illuminate\Database\Eloquent\Collection $servers
*/
class Mount extends Model
{
@ -94,4 +95,14 @@ class Mount extends Model
{
return $this->belongsToMany(Node::class);
}
/**
* Returns all servers that have this mount assigned.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function servers()
{
return $this->belongsToMany(Server::class);
}
}

View file

@ -53,6 +53,7 @@ use Znck\Eloquent\Traits\BelongsToThrough;
* @property \Pterodactyl\Models\DaemonKey[]|\Illuminate\Database\Eloquent\Collection $keys
* @property \Pterodactyl\Models\ServerTransfer $transfer
* @property \Pterodactyl\Models\Backup[]|\Illuminate\Database\Eloquent\Collection $backups
* @property \Pterodactyl\Models\Mount[]|\Illuminate\Database\Eloquent\Collection $mounts
*/
class Server extends Model
{
@ -351,4 +352,14 @@ class Server extends Model
{
return $this->hasMany(Backup::class);
}
/**
* Returns all mounts that have this server has mounted.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function mounts()
{
return $this->belongsToMany(Mount::class);
}
}