b2in/app/Livewire/Web/Components/Sections/Portfolio.php
2026-04-10 17:18:17 +02:00

74 lines
1.7 KiB
PHP

<?php
namespace App\Livewire\Web\Components\Sections;
use Livewire\Component;
class Portfolio extends Component
{
public string $activeFilter = 'alle';
public ?array $selectedProject = null;
public bool $showModal = false;
public $content = [];
public $theme = '';
public $filters = [];
public function mount()
{
$filters = [
'alle' => 'Alle',
'villen' => 'Villen',
'penthouse' => 'Penthouse',
'loft' => 'Loft',
];
$this->filters = $filters;
$this->activeFilter = 'alle';
$this->theme = config('app.theme', 'b2in');
$portfolio = cms_theme_section('portfolio', $this->theme);
if (! is_array($portfolio)) {
$portfolio = [];
}
$this->content = $portfolio;
$this->filters = $portfolio['filters'] ?? $filters;
}
public function filterBy(string $category): void
{
$this->activeFilter = $category;
}
public function openModal(array $project): void
{
$this->selectedProject = $project;
$this->showModal = true;
}
public function closeModal(): void
{
$this->showModal = false;
$this->selectedProject = null;
}
public function getFilteredProjects(): array
{
$projects = $this->content['projects'] ?? [];
if ($this->activeFilter === 'alle') {
return $projects;
}
return array_filter($projects, function ($project) {
return strtolower($project['category']) === strtolower($this->activeFilter);
});
}
public function render()
{
return view('livewire.web.components.sections.portfolio');
}
}