fix somes

This commit is contained in:
K Muller 2026-02-13 11:36:36 +01:00
parent 2ca0e9a315
commit 5891f74d01
2 changed files with 8 additions and 7 deletions

View file

@ -30,9 +30,11 @@ trait HasCache
});
/** @phpstan-ignore-next-line */
if (method_exists(static::class, 'initializeSoftDeletes')) {
/** @phpstan-ignore-next-line */
static::restored(function () {
self::resetCache();
});
/** @phpstan-ignore-next-line */
static::forceDeleted(function () {
self::resetCache();
});
@ -58,11 +60,12 @@ trait HasCache
public static function getModelsCached(): \Illuminate\Database\Eloquent\Collection
{
return Cache::remember(static::getCacheKey(), 86400, function () {
/** @var \Illuminate\Database\Eloquent\Model $class */
/** @var class-string<static> $class */
$class = static::class;
/** @phpstan-ignore-next-line */
return $class::query()
->when(
/** @phpstan-ignore-next-line */
property_exists($class, 'cacheRelations') && is_array($class::$cacheRelations),
function ($query) use ($class) {
$query->with($class::$cacheRelations);
@ -77,7 +80,7 @@ trait HasCache
*
* @return string
*/
private static function getCacheKey(): string
public static function getCacheKey(): string
{
return sprintf("cache_%s", str_replace('\\', '_', static::class));
}

View file

@ -25,18 +25,16 @@ class NewsNextEventComponent extends Component
/** @var \App\Models\NewsTag|null $eventTag */
$eventTag = NewsTag::getTagsByCategoryInCurrentLocale($newsCategory->slug)
->filter(
fn(\Illuminate\Database\Eloquent\Model $tag) =>
$tag instanceof \App\Models\NewsTag && $tag->getTranslation('slug', 'fr') === "evenement"
fn(\Illuminate\Database\Eloquent\Model $tag) => $tag->getTranslation('slug', 'fr') === "evenement"
)
->first();
$eventTagId = $eventTag ? $eventTag->id : null;
/** @var \Illuminate\Support\Collection<int, \App\Models\News> $nextEvents */
$this->nextEvents = News::getPublishedNewsByCategoryInCurrentLocale($newsCategory->slug)
->filter(function ($news) use ($eventTagId) {
return $news->tags->contains(
fn($tag) => $tag instanceof \App\Models\NewsTag && $eventTagId === $tag->id
fn($tag) => $eventTagId === $tag->id
);
})
->sortByDesc('published_at')