52 lines
1.6 KiB
PHP
52 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\View\Components\Front\News;
|
|
|
|
use Closure;
|
|
use App\Models\News;
|
|
use App\Models\NewsCategory;
|
|
use Illuminate\View\Component;
|
|
use App\Enums\News\NewsStatusEnum;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\App;
|
|
|
|
class NewsNextEventComponent extends Component
|
|
{
|
|
public $nextEvents;
|
|
|
|
/**
|
|
* Create a new component instance.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$locale = App::getLocale();
|
|
|
|
$eventCategoryId = Cache::remember('eventCategoryId', 86400, function () {
|
|
return NewsCategory::where('slug->fr', 'evenement')
|
|
->whereNull('deleted_at')
|
|
->value('id'); #FIXME: REPLACE CATEGORY PAR TAG
|
|
});
|
|
|
|
$this->nextEvents = Cache::remember("{$locale}_newsNextEvents", 86400, function () use ($eventCategoryId) {
|
|
return News::getPublishedNewsInCurrentLocale()
|
|
->where('status', NewsStatusEnum::published)->with('categories')
|
|
->whereHas('categories', function ($query) use ($eventCategoryId) {
|
|
$query->where('category_id', $eventCategoryId); #FIXME: WHERE CATEGORY IS 'Actualites' AND WHERE TAG IS '3 (evenement)'
|
|
})
|
|
->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
|
|
]);
|
|
}
|
|
}
|