Files
ntspi-app/app/Services/Filament/Traits/SeoGenerate.php
T
F4ilji c01016a154 Migrate backend to Porto architecture and fix minor bugs
- Fully transitioned the backend to the Porto architectural pattern
- Improved code organization and maintainability
- Fixed minor bugs and inconsistencies
2025-05-12 08:47:43 +05:00

35 lines
912 B
PHP

<?php
namespace App\Services\Filament\Traits;
use App\Services\Filament\Domain\Seo\SeoGeneratorService;
use App\Ship\Contracts\SeoDescriptionInterface;
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->title,
'content' => $record instanceof SeoDescriptionInterface
? $record->getSeoDescription()
: $record->content,
'preview' => $record->preview,
]);
}
}