Fix exception thrown when accessing /nests/:id/eggs/:id API endpoint
This commit is contained in:
parent
e7e50bc45d
commit
620c624e6f
3 changed files with 16 additions and 8 deletions
|
@ -3,6 +3,10 @@ This file is a running track of new features and fixes to each version of the pa
|
|||
|
||||
This project follows [Semantic Versioning](http://semver.org) guidelines.
|
||||
|
||||
## v0.7.2 (Derelict Dermodactylus)
|
||||
### Fixed
|
||||
* Fixes an exception thrown when trying to access the `/nests/:id/eggs/:id` API endpoint.
|
||||
|
||||
## v0.7.1 (Derelict Dermodactylus)
|
||||
### Fixed
|
||||
* Fixes an exception when no token is entered on the 2-Factor enable/disable page and the form is submitted.
|
||||
|
|
|
@ -9,6 +9,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
|||
use Pterodactyl\Exceptions\PterodactylException;
|
||||
use Pterodactyl\Http\Middleware\Api\ApiSubstituteBindings;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\Routing\Exception\InvalidParameterException;
|
||||
|
||||
abstract class ApplicationApiRequest extends FormRequest
|
||||
{
|
||||
|
@ -76,22 +77,23 @@ abstract class ApplicationApiRequest extends FormRequest
|
|||
}
|
||||
|
||||
/**
|
||||
* Grab a model from the route parameters. If no model exists under
|
||||
* the specified key a default response is returned.
|
||||
* Grab a model from the route parameters. If no model is found in the
|
||||
* binding mappings an exception will be thrown.
|
||||
*
|
||||
* @param string $model
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Symfony\Component\Routing\Exception\InvalidParameterException
|
||||
*/
|
||||
public function getModel(string $model, $default = null)
|
||||
public function getModel(string $model)
|
||||
{
|
||||
$parameterKey = array_get(array_flip(ApiSubstituteBindings::getMappings()), $model);
|
||||
|
||||
if (! is_null($parameterKey)) {
|
||||
$model = $this->route()->parameter($parameterKey);
|
||||
if (is_null($parameterKey)) {
|
||||
throw new InvalidParameterException;
|
||||
}
|
||||
|
||||
return $model ?? $default;
|
||||
return $this->route()->parameter($parameterKey);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Pterodactyl\Http\Requests\Api\Application\Nests\Eggs;
|
||||
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\Nest;
|
||||
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
||||
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
|
@ -24,6 +26,6 @@ class GetEggRequest extends ApplicationApiRequest
|
|||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
return $this->getModel('nest')->id === $this->getModel('egg')->nest_id;
|
||||
return $this->getModel(Nest::class)->id === $this->getModel(Egg::class)->nest_id;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue