Path: blob/1.0-develop/app/Http/Middleware/Api/Client/SubstituteClientBindings.php
14044 views
<?php12namespace Pterodactyl\Http\Middleware\Api\Client;34use Pterodactyl\Models\Server;5use Illuminate\Routing\Middleware\SubstituteBindings;67class SubstituteClientBindings extends SubstituteBindings8{9/**10* @param \Illuminate\Http\Request $request11*/12public function handle($request, \Closure $next): mixed13{14// Override default behavior of the model binding to use a specific table15// column rather than the default 'id'.16$this->router->bind('server', function ($value) {17return Server::query()18->when(19str_starts_with($value, 'serv_'),20fn ($builder) => $builder->whereIdentifier($value),21fn ($builder) => $builder->where(strlen($value) === 8 ? 'uuidShort' : 'uuid', $value)22)23->firstOrFail();24});2526$this->router->bind('user', function ($value, $route) {27/** @var \Pterodactyl\Models\Subuser $match */28$match = $route->parameter('server')29->subusers()30->whereRelation('user', 'uuid', '=', $value)31->firstOrFail();3233return $match->user;34});3536return parent::handle($request, $next);37}38}394041