categories = collect(NewsCategoryEnum::toArray()) ->map(fn($category) => NewsCategoryEnum::make((int) $category->value)) ->filter(fn($categoryLocal) => $categoryLocal->categoriesWithLocal()) ->map(fn($categoryLocal) => [ 'title' => __($categoryLocal->label()), 'tag' => Str::slug($categoryLocal->value), 'category' => 'news', ]) ->values() ->toArray(); $this->years = collect(NewsYearsEnum::toArray()) ->map(fn($year) => NewsYearsEnum::make((int) $year->value)) ->filter(fn($yearLocal) => $yearLocal->yearsWithLocal()) ->map(fn($yearLocal) => [ 'title' => __($yearLocal->label()), 'tag' => Str::slug($yearLocal->value), 'category' => 'news', ]) ->values() ->toArray(); /** @var \Illuminate\Database\Eloquent\Builder<\App\Models\News> $query */ $query = News::query()->with('categories'); /** Sort columns with a query */ $bladeHelper->runSortQuery($query); /** Custom pagination */ $this->newsModels = $bladeHelper->runPaginate($query); } /** * Get the view / contents that represent the component. * * @return View|Closure|string */ public function render(): View|Closure|string { return view('components.front.news.index-news-component', [ 'categories' => $this->categories, 'years' => $this->years, 'newsModels' => $this->newsModels ]); } }