mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 01:44:45 +02:00

* Not found property rule * Make these “better” * Day 1 * Day 2 * Day 3 * Dat 4 * Remove disabled check * Day 4 continued * Run pint * Final changes hopefully * Pint fixes * Fix again * Reset these * Update app/Filament/Admin/Pages/Health.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> * Update app/Traits/CheckMigrationsTrait.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> --------- Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Transformers\Api\Application;
|
|
|
|
use App\Models\Node;
|
|
use App\Models\Database;
|
|
use App\Models\DatabaseHost;
|
|
use League\Fractal\Resource\Collection;
|
|
use League\Fractal\Resource\NullResource;
|
|
|
|
class DatabaseHostTransformer extends BaseTransformer
|
|
{
|
|
protected array $availableIncludes = [
|
|
'databases',
|
|
'nodes',
|
|
];
|
|
|
|
/**
|
|
* Return the resource name for the JSONAPI output.
|
|
*/
|
|
public function getResourceName(): string
|
|
{
|
|
return DatabaseHost::RESOURCE_NAME;
|
|
}
|
|
|
|
/**
|
|
* @param DatabaseHost $model
|
|
*/
|
|
public function transform($model): array
|
|
{
|
|
return [
|
|
'id' => $model->id,
|
|
'name' => $model->name,
|
|
'host' => $model->host,
|
|
'port' => $model->port,
|
|
'username' => $model->username,
|
|
'created_at' => $model->created_at->toAtomString(),
|
|
'updated_at' => $model->updated_at->toAtomString(),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Include the databases associated with this host.
|
|
*/
|
|
public function includeDatabases(DatabaseHost $model): Collection|NullResource
|
|
{
|
|
if (!$this->authorize(Database::RESOURCE_NAME)) {
|
|
return $this->null();
|
|
}
|
|
|
|
$model->loadMissing('databases');
|
|
|
|
return $this->collection($model->getRelation('databases'), $this->makeTransformer(ServerDatabaseTransformer::class), Database::RESOURCE_NAME);
|
|
}
|
|
|
|
/**
|
|
* Include the nodes associated with this host.
|
|
*/
|
|
public function includeNodes(DatabaseHost $model): Collection|NullResource
|
|
{
|
|
if (!$this->authorize(Node::RESOURCE_NAME)) {
|
|
return $this->null();
|
|
}
|
|
|
|
$model->loadMissing('nodes');
|
|
|
|
return $this->collection($model->getRelation('nodes'), $this->makeTransformer(NodeTransformer::class), Node::RESOURCE_NAME);
|
|
}
|
|
}
|