categories = collect(NewsCategory::all()) ->map(fn($categoryLocal) => [ 'title' => $categoryLocal->name, 'tag' => $categoryLocal->slug, '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' => trans($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); /** * Cette section est à revoir mais c'est pour coller et être iso au site actuellement en prod */ $currentRoute = Route::currentRouteName(); // Common values $this->postContainer = [ 'secondaryClass' => 'fw-container no-bottom-padding', 'tertiaryClass' => 'tagged-posts', 'list_type' => 'news', 'id' => 'news', 'post_id' => '9', // FIXME: probablement plus utile 'slug' => 'news', 'localized' => 'ajax_load_more_news_vars', // FIXME: probablement pas utile 'object' => 'ajax_load_more_news', // FIXME: probablement pas utile ]; switch ($currentRoute) { case 'front.news.index': $this->postContainer['load_more'] = ucfirst(__('front.buttons.see_more_news')); break; case 'front.dynamic-pages.espace-presse': $this->postContainer = array_merge($this->postContainer, [ 'class' => 'fw-container no-top-padding', 'load_more' => ucfirst(__('front.buttons.see_more_docs')), 'type_button' => true ]); break; default: $this->postContainer['load_more'] = __('front.buttons.load_more'); break; } } /** * 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, 'postContainer' => $this->postContainer ]); } }