misc_pterodactyl-panel/app/Repositories/Eloquent/ServerRepository.php

43 lines
1.2 KiB
PHP
Raw Normal View History

<?php
2017-07-15 11:52:34 -05:00
namespace Pterodactyl\Repositories\Eloquent;
2017-07-15 11:52:34 -05:00
use Pterodactyl\Models\Server;
2019-12-16 21:02:30 -08:00
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
2017-07-15 11:52:34 -05:00
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
class ServerRepository extends EloquentRepository implements ServerRepositoryInterface
{
/**
* Return the model backing this repository.
2017-07-15 11:52:34 -05:00
*/
public function model(): string
2017-07-15 11:52:34 -05:00
{
return Server::class;
}
/**
* Return a server by UUID.
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function getByUuid(string $uuid): Server
{
try {
2019-12-16 21:02:30 -08:00
/** @var \Pterodactyl\Models\Server $model */
$model = $this->getBuilder()
->with('nest', 'node')
->where(function (Builder $query) use ($uuid) {
$query->where('uuidShort', $uuid)->orWhere('uuid', $uuid);
})
->firstOrFail($this->getColumns());
return $model;
} catch (ModelNotFoundException) {
2021-01-23 12:33:34 -08:00
throw new RecordNotFoundException();
}
}
}