pelican-panel-mirror/app/Services/Nodes/NodeCreationService.php
2024-03-16 21:34:09 -04:00

26 lines
647 B
PHP

<?php
namespace App\Services\Nodes;
use Ramsey\Uuid\Uuid;
use Illuminate\Support\Str;
use App\Models\Node;
use Illuminate\Contracts\Encryption\Encrypter;
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'] = app(Encrypter::class)->encrypt(Str::random(Node::DAEMON_TOKEN_LENGTH));
$data['daemon_token_id'] = Str::random(Node::DAEMON_TOKEN_ID_LENGTH);
return Node::query()->create($data);
}
}