diff --git a/app/Http/Controllers/Admin/Mounts/MountController.php b/app/Http/Controllers/Admin/Mounts/MountController.php index 898293bbd..977dd558c 100644 --- a/app/Http/Controllers/Admin/Mounts/MountController.php +++ b/app/Http/Controllers/Admin/Mounts/MountController.php @@ -2,23 +2,23 @@ namespace Pterodactyl\Http\Controllers\Admin\Mounts; -use Pterodactyl\Contracts\Repository\LocationRepositoryInterface; use Pterodactyl\Http\Controllers\Controller; +use Pterodactyl\Repositories\Eloquent\MountRepository; class MountController extends Controller { /** - * @var \Pterodactyl\Contracts\Repository\LocationRepositoryInterface + * @var \Pterodactyl\Repositories\Eloquent\MountRepository */ protected $repository; /** - * LocationController constructor. + * MountController constructor. * - * @param \Pterodactyl\Contracts\Repository\LocationRepositoryInterface $repository + * @param \Pterodactyl\Repositories\Eloquent\MountRepository $repository */ public function __construct( - LocationRepositoryInterface $repository + MountRepository $repository ) { $this->repository = $repository; } @@ -31,7 +31,7 @@ class MountController extends Controller public function index() { return view('admin.mounts.index', [ - 'locations' => $this->repository->getAllWithDetails(), + 'mounts' => $this->repository->getAllWithDetails(), ]); } } diff --git a/app/Models/Mount.php b/app/Models/Mount.php index 426c32bc4..6c3e699fe 100644 --- a/app/Models/Mount.php +++ b/app/Models/Mount.php @@ -3,7 +3,16 @@ namespace Pterodactyl\Models; /** - * @property int $id + * @property string $id + * @property string $name + * @property string $description + * @property string $source + * @property string $target + * @property bool $read_only + * @property bool $user_mountable + * + * @property \Illuminate\Database\Eloquent\Relations\BelongsToMany $nodes + * @property \Illuminate\Database\Eloquent\Relations\BelongsToMany $eggs */ class Mount extends Model { @@ -25,5 +34,50 @@ class Mount extends Model * * @var array */ - protected $guarded = ['id']; + protected $guarded = ['id', 'name', 'description', 'source', 'target']; + + /** + * Default values for specific fields in the database. + * + * @var array + */ + protected $attributes = [ + 'read_only' => 'bool', + 'user_mountable' => 'bool', + ]; + + /** + * Rules verifying that the data being stored matches the expectations of the database. + * + * @var string + */ + public static $validationRules = [ + 'id' => 'required|string|size:36|unique:mounts,id', + 'name' => 'required|string|min:2|max:64|unique:mounts,name', + 'description' => 'nullable|string|max:255', + 'source' => 'required|string', + 'target' => 'required|string', + 'read_only' => 'sometimes|boolean', + 'user_mountable' => 'sometimes|boolean', + ]; + + /** + * Returns all eggs that have this mount assigned. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function eggs() + { + return $this->belongsToMany(Egg::class); + } + + /** + * Returns all nodes that have this mount assigned. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function nodes() + { + return $this->belongsToMany(Node::class); + } } diff --git a/app/Repositories/Eloquent/MountRepository.php b/app/Repositories/Eloquent/MountRepository.php new file mode 100644 index 000000000..2bf953566 --- /dev/null +++ b/app/Repositories/Eloquent/MountRepository.php @@ -0,0 +1,32 @@ +getBuilder()->withCount('eggs', 'nodes')->get($this->getColumns()); + } +} diff --git a/database/migrations/2020_05_20_234655_add_mounts_table.php b/database/migrations/2020_05_20_234655_add_mounts_table.php new file mode 100644 index 000000000..308ed685b --- /dev/null +++ b/database/migrations/2020_05_20_234655_add_mounts_table.php @@ -0,0 +1,48 @@ +char('id', 36)->unique(); + $table->string('name'); + $table->text('description')->nullable(); + $table->string('source'); + $table->string('target'); + $table->tinyInteger('read_only')->unsigned(); + $table->tinyInteger('user_mountable')->unsigned(); + }); + + Schema::create('egg_mount', function (Blueprint $table) { + $table->increments('egg_id')->unique(); + $table->char('mount_id', 36)->unique(); + }); + + Schema::create('mount_node', function (Blueprint $table) { + $table->increments('node_id')->unique(); + $table->char('mount_id', 36)->unique(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('mount_node'); + Schema::dropIfExists('egg_mount'); + Schema::dropIfExists('mounts'); + } +} diff --git a/resources/views/admin/mounts/index.blade.php b/resources/views/admin/mounts/index.blade.php index ba6701eac..6b9364b91 100644 --- a/resources/views/admin/mounts/index.blade.php +++ b/resources/views/admin/mounts/index.blade.php @@ -3,6 +3,7 @@ {{-- This software is licensed under the terms of the MIT license. --}} {{-- https://opensource.org/licenses/MIT --}} + @extends('layouts.admin') @section('title') @@ -25,7 +26,7 @@
{{ $location->id }}
{{ $mount->id }}