Add nests & eggs
Cleanup middleware handling and parameters on controllers...
This commit is contained in:
parent
de07b3cc7f
commit
8afced3410
26 changed files with 737 additions and 446 deletions
|
@ -3,11 +3,33 @@
|
|||
namespace Pterodactyl\Http\Middleware\Api;
|
||||
|
||||
use Closure;
|
||||
use Pterodactyl\Models\Egg;
|
||||
use Pterodactyl\Models\Nest;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Pterodactyl\Models\Database;
|
||||
use Pterodactyl\Models\Location;
|
||||
use Pterodactyl\Models\Allocation;
|
||||
use Illuminate\Routing\Middleware\SubstituteBindings;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class ApiSubstituteBindings extends SubstituteBindings
|
||||
{
|
||||
/**
|
||||
* Mappings to automatically assign route parameters to a model.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $mappings = [
|
||||
'allocation' => Allocation::class,
|
||||
'database' => Database::class,
|
||||
'egg' => Egg::class,
|
||||
'location' => Location::class,
|
||||
'nest' => Nest::class,
|
||||
'node' => Node::class,
|
||||
'server' => Server::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Perform substitution of route parameters without triggering
|
||||
* a 404 error if a model is not found.
|
||||
|
@ -20,6 +42,10 @@ class ApiSubstituteBindings extends SubstituteBindings
|
|||
{
|
||||
$route = $request->route();
|
||||
|
||||
foreach (self::$mappings as $key => $model) {
|
||||
$this->router->model($key, $model);
|
||||
}
|
||||
|
||||
$this->router->substituteBindings($route);
|
||||
|
||||
// Attempt to resolve bindings for this route. If one of the models
|
||||
|
@ -35,4 +61,14 @@ class ApiSubstituteBindings extends SubstituteBindings
|
|||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the registered mappings.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getMappings()
|
||||
{
|
||||
return self::$mappings;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue