38 lines
959 B
PHP
38 lines
959 B
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace App\Services\DocumentationVersion;
|
|
|
|
use App\Models\DocumentationVersion;
|
|
use App\Models\Project;
|
|
use Illuminate\Support\Str;
|
|
|
|
final readonly class DocumentationVersionCommandHandler
|
|
{
|
|
public function handleStore(Project $project, array $data): DocumentationVersion
|
|
{
|
|
$data['slug'] = Str::lower($data['slug']);
|
|
|
|
return $project->documentationVersions()->create($data);
|
|
}
|
|
|
|
public function handleUpdate(DocumentationVersion $version, array $data): DocumentationVersion
|
|
{
|
|
if (isset($data['slug'])) {
|
|
$data['slug'] = Str::lower($data['slug']);
|
|
}
|
|
|
|
$version->update($data);
|
|
$version->touch();
|
|
|
|
return $version;
|
|
}
|
|
|
|
public function handleDestroy(DocumentationVersion $version): void
|
|
{
|
|
$version->update([
|
|
'slug' => $version->slug . '#delete:' . $version->id,
|
|
]);
|
|
$version->delete();
|
|
}
|
|
}
|