Rework admin panel and other

This commit is contained in:
F4ilji
2025-04-02 18:37:20 +05:00
parent 49072e50c7
commit 5cd6ff11b5
198 changed files with 9715 additions and 6664 deletions
@@ -5,6 +5,7 @@ namespace App\Services\Filament\Domain\Posts;
use App\Dto\MainSliderDTO;
use App\Models\MainSlider;
use App\Models\Post;
use App\Models\Slide;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
@@ -23,7 +24,8 @@ class PostSliderService
public function create(): void
{
try {
$this->post->mainSlider()->create([
$post = Post::find($this->post->id);
$slide = new Slide([
'title' => $this->dto->title,
'content' => $this->dto->content,
'image' => $this->dto->image,
@@ -33,11 +35,13 @@ class PostSliderService
'is_active' => $this->dto->is_active,
'start_time' => $this->dto->start_time,
'end_time' => $this->dto->end_time,
'slider_id' => $this->dto->slider_id,
]);
$post->slide()->save($slide);
Log::info('MainSlider created successfully', ['postTitle' => $this->post->title]);
Log::info('Slide created successfully', ['postTitle' => $this->post->title]);
} catch (\Exception $e) {
Log::error('Failed to create MainSlider', [
Log::error('Failed to create slide', [
'postTitle' => $this->post->title,
'error' => $e->getMessage(),
]);
@@ -53,31 +57,20 @@ class PostSliderService
public function update(): void
{
try {
// Retrieve the MainSlider instance
$mainSlider = $this->post->mainSlider;
$post = Post::find($this->post->id);
$post->slide()->update([
'title' => $this->dto->title,
'content' => $this->dto->content,
'image' => $this->dto->image,
'link' => $this->generatePostLink(),
'settings' => $this->dto->settings,
'color_theme' => $this->dto->color_theme,
'is_active' => $this->dto->is_active,
'start_time' => $this->dto->start_time,
'end_time' => $this->dto->end_time,
'slider_id' => $this->dto->slider_id,
]);
if ($mainSlider) {
// Update properties and save to trigger model events
$mainSlider->fill([
'title' => $this->dto->title,
'content' => $this->dto->content,
'image' => $this->dto->image,
'link' => $this->generatePostLink(),
'settings' => $this->dto->settings,
'color_theme' => $this->dto->color_theme,
'is_active' => $this->dto->is_active,
'start_time' => $this->dto->start_time,
'end_time' => $this->dto->end_time,
]);
$mainSlider->save(); // This will trigger updating and updated observer events
Log::info('MainSlider updated successfully', ['postTitle' => $this->post->title]);
} else {
Log::warning('MainSlider not found for update', ['postTitle' => $this->post->title]);
}
} catch (\Exception $e) {
Log::error('Failed to update MainSlider', [
'postTitle' => $this->post->title,
@@ -0,0 +1,95 @@
<?php
namespace App\Services\Filament\Domain\Seo;
use Illuminate\Support\Str;
class SeoGeneratorService
{
/**
*
* @param array $data
* @return array
*/
public function generate(array $data): array
{
return [
'title' => $this->extractSeoTitle($data),
'description' => $this->extractSeoDescription($data['content']),
'image' => $this->extractSeoImage($data),
];
}
/**
* Извлекает SEO-заголовок.
*
* @param array $data
* @return string
*/
private function extractSeoTitle(array $data): string
{
return $data['title'];
}
/**
* Извлекает SEO-описание.
*
* @param array $content
* @return string
*/
private function extractSeoDescription(array $content): string
{
$rowData = $this->getBlockBySeoActiveState('paragraph', $content);
if ($rowData === null) {
$rowData = $this->getFirstBlockByName('paragraph', $content);
}
$description = $rowData ? html_entity_decode(strip_tags($rowData['data']['content'])) : '';
return Str::limit(htmlspecialchars($description, ENT_QUOTES, 'UTF-8'), 160);
}
/**
* Извлекает SEO-изображение.
*
* @param array $data
* @return string|null
*/
private function extractSeoImage(array $data): ?string
{
return $data['preview'] ?? null;
}
/**
* Находит первый блок по имени.
*
* @param string $name
* @param array $content
* @return array|null
*/
private function getFirstBlockByName(string $name, array $content): ?array
{
foreach ($content as $block) {
if ($block['type'] === $name) {
return $block;
}
}
return null;
}
/**
* Находит блок по SEO-активности.
*
* @param string $name
* @param array $content
* @return array|null
*/
private function getBlockBySeoActiveState(string $name, array $content): ?array
{
foreach ($content as $block) {
if ($block['type'] === $name && ($block['data']['seo_active'] ?? false)) {
return $block;
}
}
return null;
}
}