Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Http/Middleware/Api/Client/SubstituteClientBindings.php
14044 views
1
<?php
2
3
namespace Pterodactyl\Http\Middleware\Api\Client;
4
5
use Pterodactyl\Models\Server;
6
use Illuminate\Routing\Middleware\SubstituteBindings;
7
8
class SubstituteClientBindings extends SubstituteBindings
9
{
10
/**
11
* @param \Illuminate\Http\Request $request
12
*/
13
public function handle($request, \Closure $next): mixed
14
{
15
// Override default behavior of the model binding to use a specific table
16
// column rather than the default 'id'.
17
$this->router->bind('server', function ($value) {
18
return Server::query()
19
->when(
20
str_starts_with($value, 'serv_'),
21
fn ($builder) => $builder->whereIdentifier($value),
22
fn ($builder) => $builder->where(strlen($value) === 8 ? 'uuidShort' : 'uuid', $value)
23
)
24
->firstOrFail();
25
});
26
27
$this->router->bind('user', function ($value, $route) {
28
/** @var \Pterodactyl\Models\Subuser $match */
29
$match = $route->parameter('server')
30
->subusers()
31
->whereRelation('user', 'uuid', '=', $value)
32
->firstOrFail();
33
34
return $match->user;
35
});
36
37
return parent::handle($request, $next);
38
}
39
}
40
41