From 5891f74d01ccd4eeda393f76d968bfa10dcebc50 Mon Sep 17 00:00:00 2001 From: K Muller Date: Fri, 13 Feb 2026 11:36:36 +0100 Subject: [PATCH] fix somes --- app/Traits/Models/HasCache.php | 9 ++++++--- .../Components/Front/News/NewsNextEventComponent.php | 6 ++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/Traits/Models/HasCache.php b/app/Traits/Models/HasCache.php index fd06c0a3..df9dfefc 100644 --- a/app/Traits/Models/HasCache.php +++ b/app/Traits/Models/HasCache.php @@ -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 $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)); } diff --git a/app/View/Components/Front/News/NewsNextEventComponent.php b/app/View/Components/Front/News/NewsNextEventComponent.php index dee69932..ae930507 100644 --- a/app/View/Components/Front/News/NewsNextEventComponent.php +++ b/app/View/Components/Front/News/NewsNextEventComponent.php @@ -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 $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')