Path: blob/1.0-develop/app/Repositories/Eloquent/SubuserRepository.php
7460 views
<?php12namespace Pterodactyl\Repositories\Eloquent;34use Pterodactyl\Models\Subuser;5use Pterodactyl\Exceptions\Repository\RecordNotFoundException;6use Pterodactyl\Contracts\Repository\SubuserRepositoryInterface;78class SubuserRepository extends EloquentRepository implements SubuserRepositoryInterface9{10/**11* Return the model backing this repository.12*/13public function model(): string14{15return Subuser::class;16}1718/**19* Return a subuser with the associated server relationship.20*/21public function loadServerAndUserRelations(Subuser $subuser, bool $refresh = false): Subuser22{23if (!$subuser->relationLoaded('server') || $refresh) {24$subuser->load('server');25}2627if (!$subuser->relationLoaded('user') || $refresh) {28$subuser->load('user');29}3031return $subuser;32}3334/**35* Return a subuser with the associated permissions relationship.36*/37public function getWithPermissions(Subuser $subuser, bool $refresh = false): Subuser38{39if (!$subuser->relationLoaded('permissions') || $refresh) {40$subuser->load('permissions');41}4243if (!$subuser->relationLoaded('user') || $refresh) {44$subuser->load('user');45}4647return $subuser;48}4950/**51* Return a subuser and associated permissions given a user_id and server_id.52*53* @throws RecordNotFoundException54*/55public function getWithPermissionsUsingUserAndServer(int $user, int $server): Subuser56{57$instance = $this->getBuilder()->with('permissions')->where([58['user_id', '=', $user],59['server_id', '=', $server],60])->first();6162if (is_null($instance)) {63throw new RecordNotFoundException();64}6566return $instance;67}68}697071