small fix
This commit is contained in:
@@ -7,43 +7,50 @@ use App\Containers\AppStructure\UI\WEB\Transformers\PageResource;
|
|||||||
use App\Ship\Contracts\SeoServiceInterface;
|
use App\Ship\Contracts\SeoServiceInterface;
|
||||||
use App\Ship\Controllers\Controller;
|
use App\Ship\Controllers\Controller;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Inertia\Inertia;
|
use Inertia\Response;
|
||||||
|
|
||||||
class PageController extends Controller
|
class PageController extends Controller
|
||||||
{
|
{
|
||||||
public function __construct(readonly SeoServiceInterface $seoPageProvider){}
|
public function __construct(readonly SeoServiceInterface $seoPageProvider){}
|
||||||
|
|
||||||
public function render(string $path): \Inertia\Response
|
public function render(string $path): Response
|
||||||
{
|
{
|
||||||
// Генерируем уникальный ключ для кеширования
|
$page = $this->getPageByPath($path);
|
||||||
$cacheKey = 'page_' . md5($path);
|
$this->handleCheckNotFoundStatusCode($page);
|
||||||
|
|
||||||
// Пытаемся получить данные из кеша
|
|
||||||
$page = Cache::remember($cacheKey, now()->addHours(48), function () use ($path) {
|
|
||||||
return Page::where('path', '=', $path)
|
|
||||||
->with('section.pages.section', 'section.mainSection')
|
|
||||||
->first();
|
|
||||||
});
|
|
||||||
|
|
||||||
if ($page === null) {
|
|
||||||
abort(404);
|
|
||||||
}
|
|
||||||
$subSectionPages = $page->section ? PageResource::collection($page->section->pages) : null;
|
$subSectionPages = $page->section ? PageResource::collection($page->section->pages) : null;
|
||||||
|
|
||||||
$seo = $this->seoPageProvider->getSeoForModel($page);
|
$seo = $this->seoPageProvider->getSeoForModel($page);
|
||||||
|
$pageResource = new PageResource($page);
|
||||||
|
$this->handlePageStatusCode($pageResource);
|
||||||
$page = new PageResource($page);
|
|
||||||
|
|
||||||
|
|
||||||
if ($page->code != 200) {
|
|
||||||
abort($page->code);
|
|
||||||
}
|
|
||||||
|
|
||||||
return inertia()->render('Page', [
|
return inertia()->render('Page', [
|
||||||
'page' => $page,
|
'page' => $pageResource,
|
||||||
'subSectionPages' => $subSectionPages,
|
'subSectionPages' => $subSectionPages,
|
||||||
'seo' => $seo,
|
'seo' => $seo,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function handlePageStatusCode(PageResource $pageResource): void
|
||||||
|
{
|
||||||
|
if ($pageResource->code != 200) {
|
||||||
|
abort($pageResource->code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function handleCheckNotFoundStatusCode($page): void
|
||||||
|
{
|
||||||
|
if ($page === null) {
|
||||||
|
abort(404);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPageByPath(string $path): ?Page
|
||||||
|
{
|
||||||
|
$cacheKey = 'page_' . md5($path);
|
||||||
|
|
||||||
|
return Cache::remember($cacheKey, now()->addHours(48), function () use ($path) {
|
||||||
|
return Page::where('path', '=', $path)
|
||||||
|
->with('section.pages.section', 'section.mainSection')
|
||||||
|
->first();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ class MainController extends Controller
|
|||||||
$event_date_start = (new DateTime())->format('Y-m-d');
|
$event_date_start = (new DateTime())->format('Y-m-d');
|
||||||
|
|
||||||
return EventThumbnailResource::collection(
|
return EventThumbnailResource::collection(
|
||||||
Event::select('title', 'slug', 'event_date_start', 'address', 'is_online', 'category_id')
|
Event::select('title', 'slug', 'event_date_start', 'event_time_start' , 'address', 'is_online', 'category_id')
|
||||||
->where('event_date_start', '>=', $event_date_start)
|
->where('event_date_start', '>=', $event_date_start)
|
||||||
->orderBy('event_date_start', 'asc')
|
->orderBy('event_date_start', 'asc')
|
||||||
->limit(3)
|
->limit(3)
|
||||||
|
|||||||
@@ -2,11 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Services\Filament\Domain\Posts;
|
namespace App\Services\Filament\Domain\Posts;
|
||||||
|
|
||||||
use App\Enums\PostStatus;
|
use App\Containers\Article\Enums\PostStatus;
|
||||||
use App\Jobs\CreateTgPost;
|
use App\Containers\Article\Models\Post;
|
||||||
use App\Jobs\CreateTgPostJob;
|
|
||||||
use App\Jobs\UpdateTgPost;
|
|
||||||
use App\Models\Post;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
|
|
||||||
<section class="max-w-screen-xl w-full mx-auto px-4 py-3 pb-10">
|
<section class="max-w-screen-xl w-full mx-auto px-4 py-3 pb-10">
|
||||||
<PostSection :posts="posts" />
|
<PostSection :posts="posts" />
|
||||||
|
<div>
|
||||||
|
<EventSection :events="events" />
|
||||||
|
</div>
|
||||||
<EducationSection :educations="educations" />
|
<EducationSection :educations="educations" />
|
||||||
</section>
|
</section>
|
||||||
<PageResourceList resource-id="glavnaia-stranica-resurs" />
|
<PageResourceList resource-id="glavnaia-stranica-resurs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user