Massively simplify API binding logic
Changes the API internals to use normal Laravel binding which automatically supports nested-models and can determine their relationships. This removes a lot of confusingly complex internal logic and replaces it with standard Laravel code. This also removes a deprecated "getModel" method and fully replaces it with a "parameter" method that does stricter type-checking.
This commit is contained in:
parent
f1235c7f88
commit
e313dff674
53 changed files with 290 additions and 604 deletions
|
@ -3,6 +3,7 @@
|
|||
namespace Pterodactyl\Providers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Pterodactyl\Models\Database;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
|
@ -26,6 +27,11 @@ class RouteServiceProvider extends ServiceProvider
|
|||
return preg_match(self::FILE_PATH_REGEX, $request->getPathInfo()) === 1;
|
||||
});
|
||||
|
||||
// This is needed to make use of the "resolveRouteBinding" functionality in the
|
||||
// model. Without it you'll never trigger that logic flow thus resulting in a 404
|
||||
// error because we request databases with a HashID, and not with a normal ID.
|
||||
Route::model('database', Database::class);
|
||||
|
||||
$this->routes(function () {
|
||||
Route::middleware(['web', 'csrf'])->group(function () {
|
||||
Route::middleware('auth')->group(base_path('routes/base.php'));
|
||||
|
@ -36,14 +42,18 @@ class RouteServiceProvider extends ServiceProvider
|
|||
Route::middleware('api')->group(function () {
|
||||
Route::middleware(['application-api', 'throttle:api.application'])
|
||||
->prefix('/api/application')
|
||||
->scopeBindings()
|
||||
->group(base_path('routes/api-application.php'));
|
||||
|
||||
Route::middleware(['client-api', 'throttle:api.client'])
|
||||
->prefix('/api/client')
|
||||
->scopeBindings()
|
||||
->group(base_path('routes/api-client.php'));
|
||||
});
|
||||
|
||||
Route::middleware('daemon')->prefix('/api/remote')
|
||||
Route::middleware('daemon')
|
||||
->prefix('/api/remote')
|
||||
->scopeBindings()
|
||||
->group(base_path('routes/api-remote.php'));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue