ldc-groupe/app/View/Components/Front/News/NewsNextEventComponent.php
2026-01-12 15:17:54 +01:00

55 lines
1.5 KiB
PHP

<?php
namespace App\View\Components\Front\News;
use Closure;
use App\Models\News;
use App\Models\NewsTag;
use App\Models\NewsCategory;
use Illuminate\View\Component;
use App\Enums\News\NewsStatusEnum;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Cache;
class NewsNextEventComponent extends Component
{
public $nextEvents;
/**
* Create a new component instance.
*/
public function __construct()
{
$locale = App::getLocale();
$newsCategory = Cache::remember('newsCategory', 86400, function () {
return NewsCategory::where('slug->fr', 'actualites')
->whereNull('deleted_at')
->value('slug');
});
$eventTagId = Cache::remember('eventTagId', 86400, function () {
return NewsTag::where('slug->fr', 'evenement')
->value('id');
});
$this->nextEvents = News::getPublishedNewsByCategoryInCurrentLocale($newsCategory)
->whereHas('tags', function ($query) use ($eventTagId) {
$query->where('newsable_id', $eventTagId);
})
->latest()
->take(3)
->get();
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.front.news.news-next-event-component', [
'nextEvents' => $this->nextEvents
]);
}
}