pelican-panel-banquise/app/Services/Nests/NestCreationService.php
2024-03-12 22:39:16 -04:00

34 lines
920 B
PHP

<?php
namespace App\Services\Nests;
use Ramsey\Uuid\Uuid;
use App\Models\Nest;
use App\Contracts\Repository\NestRepositoryInterface;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
class NestCreationService
{
/**
* NestCreationService constructor.
*/
public function __construct(private ConfigRepository $config, private NestRepositoryInterface $repository)
{
}
/**
* Create a new nest on the system.
*
* @throws \App\Exceptions\Model\DataValidationException
*/
public function handle(array $data, string $author = null): Nest
{
return $this->repository->create([
'uuid' => Uuid::uuid4()->toString(),
'author' => $author ?? $this->config->get('panel.service.author'),
'name' => array_get($data, 'name'),
'description' => array_get($data, 'description'),
], true, true);
}
}