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