Files
ntspi-app/app/Services/Filament/Traits/SeoGenerate.php
T
2025-05-25 19:01:00 +05:00

38 lines
1.0 KiB
PHP

<?php
namespace App\Services\Filament\Traits;
use App\Services\Filament\Domain\Seo\SeoGeneratorService;
use App\Ship\Contracts\SeoDescriptionInterface;
use App\Ship\Contracts\SeoTitleInterface;
trait SeoGenerate
{
public function createSeo($record): void
{
$seo = $this->generateSeoData($record);
$record->seo()->create($seo);
}
public function updateSeo($record): void
{
if ($record->seo()->exists()) {
$record->seo()->update($this->generateSeoData($record));
} else {
$this->createSeo($record);
}
}
private function generateSeoData($record) {
return app(SeoGeneratorService::class)->generate([
'title' => $record instanceof SeoTitleInterface
? $record->getSeoTitle()
: $record->title,
'content' => $record instanceof SeoDescriptionInterface
? $record->getSeoDescription()
: $record->content,
'preview' => $record->preview,
]);
}
}