Properly setup Mount model, add database migration, get mount admin page added

This commit is contained in:
Matthew Penner 2020-05-20 18:00:53 -06:00
parent 59a150148a
commit 00d1b5861a
5 changed files with 169 additions and 27 deletions

View file

@ -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(),
]);
}
}

View file

@ -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);
}
}

View file

@ -0,0 +1,32 @@
<?php
namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\Mount;
use Illuminate\Support\Collection;
use Pterodactyl\Repositories\Concerns\Searchable;
class MountRepository extends EloquentRepository
{
use Searchable;
/**
* Return the model backing this repository.
*
* @return string
*/
public function model()
{
return Mount::class;
}
/**
* Return mounts with a count of eggs, nodes, and servers attached to it.
*
* @return \Illuminate\Support\Collection
*/
public function getAllWithDetails(): Collection
{
return $this->getBuilder()->withCount('eggs', 'nodes')->get($this->getColumns());
}
}