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

52 lines
1.4 KiB
PHP
Raw Normal View History

<?php
2017-09-26 02:43:01 +00:00
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
2017-09-26 02:43:01 +00:00
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
*/
2017-07-15 16:52:34 +00:00
namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\Nest;
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
2017-08-05 22:26:30 +00:00
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
2017-07-15 16:52:34 +00:00
class NestRepository extends EloquentRepository implements NestRepositoryInterface
{
/**
* Return the model backing this repository.
*
* @return string
2017-07-15 16:52:34 +00:00
*/
public function model()
{
return Nest::class;
2017-07-15 16:52:34 +00:00
}
/**
* Return a nest or all nests with their associated eggs and variables.
2017-10-04 04:31:04 +00:00
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function getWithEggs(int $id = null): Nest
2017-07-15 16:52:34 +00:00
{
$instance = $this->getBuilder()->with('eggs', 'eggs.variables');
2017-07-15 16:52:34 +00:00
2021-01-23 20:33:34 +00:00
if (!is_null($id)) {
/** @var \Pterodactyl\Models\Nest|null $instance */
2017-07-15 16:52:34 +00:00
$instance = $instance->find($id, $this->getColumns());
2021-01-23 20:33:34 +00:00
if (!$instance) {
throw new RecordNotFoundException();
2017-07-15 16:52:34 +00:00
}
return $instance;
}
/* @noinspection PhpIncompatibleReturnTypeInspection */
// @phpstan-ignore-next-line
2017-07-15 16:52:34 +00:00
return $instance->get($this->getColumns());
}
}