Add increment id to mount, add basic mount view page
This commit is contained in:
parent
976b669059
commit
77150b2551
8 changed files with 203 additions and 12 deletions
|
@ -54,6 +54,21 @@ class MountController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the mount view page.
|
||||
*
|
||||
* @param string $id
|
||||
* @return \Illuminate\View\View
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function view($id)
|
||||
{
|
||||
return view('admin.mounts.view', [
|
||||
'mount' => $this->repository->getWithRelations($id),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle request to create new mount.
|
||||
*
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
namespace Pterodactyl\Models;
|
||||
|
||||
/**
|
||||
* @property string $id
|
||||
* @property int $id
|
||||
* @property string $uuid
|
||||
* @property string $name
|
||||
* @property string $description
|
||||
* @property string $source
|
||||
|
@ -11,8 +12,8 @@ namespace Pterodactyl\Models;
|
|||
* @property bool $read_only
|
||||
* @property bool $user_mountable
|
||||
*
|
||||
* @property \Illuminate\Database\Eloquent\Relations\BelongsToMany $nodes
|
||||
* @property \Illuminate\Database\Eloquent\Relations\BelongsToMany $eggs
|
||||
* @property \Illuminate\Database\Eloquent\Relations\BelongsToMany $nodes
|
||||
*/
|
||||
class Mount extends Model
|
||||
{
|
||||
|
@ -34,7 +35,7 @@ class Mount extends Model
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id', 'name', 'description', 'source', 'target'];
|
||||
protected $guarded = ['id', 'uuid', 'name', 'description', 'source', 'target'];
|
||||
|
||||
/**
|
||||
* Default values for specific fields in the database.
|
||||
|
@ -42,6 +43,12 @@ class Mount extends Model
|
|||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'id' => 'int',
|
||||
'uuid' => 'string',
|
||||
'name' => 'string',
|
||||
'description' => 'string',
|
||||
'source' => 'string',
|
||||
'target' => 'string',
|
||||
'read_only' => 'bool',
|
||||
'user_mountable' => 'bool',
|
||||
];
|
||||
|
@ -52,7 +59,7 @@ class Mount extends Model
|
|||
* @var string
|
||||
*/
|
||||
public static $validationRules = [
|
||||
// 'id' => 'required|string|size:36|unique:mounts,id',
|
||||
// 'uuid' => 'required|string|size:36|unique:mounts,uuid',
|
||||
'name' => 'required|string|min:2|max:64|unique:mounts,name',
|
||||
'description' => 'nullable|string|max:255',
|
||||
'source' => 'required|string',
|
||||
|
|
|
@ -5,6 +5,8 @@ namespace Pterodactyl\Repositories\Eloquent;
|
|||
use Pterodactyl\Models\Mount;
|
||||
use Illuminate\Support\Collection;
|
||||
use Pterodactyl\Repositories\Concerns\Searchable;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
|
||||
|
||||
class MountRepository extends EloquentRepository
|
||||
{
|
||||
|
@ -29,4 +31,21 @@ class MountRepository extends EloquentRepository
|
|||
{
|
||||
return $this->getBuilder()->withCount('eggs', 'nodes')->get($this->getColumns());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all of the mounts and their respective relations.
|
||||
*
|
||||
* @param string $id
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
*/
|
||||
public function getWithRelations(string $id): Mount
|
||||
{
|
||||
try {
|
||||
return $this->getBuilder()->with('eggs', 'nodes')->findOrFail($id, $this->getColumns());
|
||||
} catch (ModelNotFoundException $exception) {
|
||||
throw new RecordNotFoundException;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class MountCreationService
|
|||
public function handle(array $data)
|
||||
{
|
||||
return $this->repository->create(array_merge($data, [
|
||||
'id' => Uuid::uuid4()->toString(),
|
||||
'uuid' => Uuid::uuid4()->toString(),
|
||||
]), true, true);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue