php-content/View/Modal/Web/Blog.php
2026-01-26 23:59:46 +00:00

62 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Core\Content\View\Modal\Web;
use Livewire\Component;
use Core\Content\Services\ContentRender;
use Core\Mod\Tenant\Models\Workspace;
use Core\Mod\Tenant\Services\WorkspaceService;
class Blog extends Component
{
public array $workspace = [];
public array $posts = [];
public bool $loading = true;
public function mount(): void
{
$workspaceService = app(WorkspaceService::class);
// Get workspace from request attributes (set by subdomain middleware)
$slug = request()->attributes->get('workspace', 'main');
$this->workspace = $workspaceService->get($slug) ?? $workspaceService->get('main');
$this->loadPosts();
}
protected function loadPosts(): void
{
try {
$workspaceModel = Workspace::where('slug', $this->workspace['slug'])->first();
if (! $workspaceModel) {
$this->posts = [];
$this->loading = false;
return;
}
$render = app(ContentRender::class);
$result = $render->getPosts($workspaceModel, page: 1, perPage: 20);
$this->posts = $result['posts'] ?? [];
} catch (\Exception $e) {
$this->posts = [];
}
$this->loading = false;
}
public function render()
{
return view('content::web.blog', [
'posts' => $this->posts,
'workspace' => $this->workspace,
])->layout('shared::layouts.satellite', [
'title' => 'Blog | '.$this->workspace['name'],
'workspace' => $this->workspace,
]);
}
}