b2in/app/Livewire/Web/Components/Sections/MagazinDetail.php
2025-10-20 17:50:35 +02:00

56 lines
1.3 KiB
PHP

<?php
namespace App\Livewire\Web\Components\Sections;
use Livewire\Component;
class MagazinDetail extends Component
{
public $articleId;
public $article;
public $relatedArticles;
public $content;
public function mount($id = 1)
{
$this->articleId = (int) $id;
$this->loadArticle();
$this->loadRelatedArticles();
$this->loadThemeContent();
}
private function loadArticle()
{
$articles = $this->getArticlesData();
$this->article = $articles[$this->articleId] ?? $articles[1];
}
private function loadRelatedArticles()
{
$articles = $this->getArticlesData();
$this->relatedArticles = collect($articles)
->filter(fn($article, $key) => $key != $this->articleId)
->take(2)
->values()
->toArray();
}
private function loadThemeContent()
{
$theme = config('app.theme', 'b2in');
$this->content = config("content.themes.{$theme}.magazin_detail", []);
}
private function getArticlesData()
{
return config('content.articles', []);
}
public function render()
{
return view('livewire.web.components.sections.magazin-detail', [
'article' => $this->article,
'relatedArticles' => $this->relatedArticles
]);
}
}