pelican-panel-mirror/app/Services/Nodes/NodeCreationService.php
2024-03-19 05:11:41 -04:00

25 lines
577 B
PHP

<?php
namespace App\Services\Nodes;
use Ramsey\Uuid\Uuid;
use Illuminate\Support\Str;
use App\Models\Node;
class NodeCreationService
{
/**
* Create a new node on the panel.
*
* @throws \App\Exceptions\Model\DataValidationException
*/
public function handle(array $data): Node
{
$data['uuid'] = Uuid::uuid4()->toString();
$data['daemon_token'] = encrypt(Str::random(Node::DAEMON_TOKEN_LENGTH));
$data['daemon_token_id'] = Str::random(Node::DAEMON_TOKEN_ID_LENGTH);
return Node::query()->create($data);
}
}