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
10277 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()->where(strlen($value) === 8 ? 'uuidShort' : 'uuid', $value)->firstOrFail();
19
});
20
21
$this->router->bind('user', function ($value, $route) {
22
/** @var \Pterodactyl\Models\Subuser $match */
23
$match = $route->parameter('server')
24
->subusers()
25
->whereRelation('user', 'uuid', '=', $value)
26
->firstOrFail();
27
28
return $match->user;
29
});
30
31
return parent::handle($request, $next);
32
}
33
}
34
35