*/ public static function getModelsCached(): \Illuminate\Database\Eloquent\Collection { return Cache::remember(static::getCacheKey(), 86400, function () { /** @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); } ) ->get(); }); } /** * Generate a unique cache key for the model. * * @return string */ public static function getCacheKey(): string { return sprintf("cache_%s", str_replace('\\', '_', static::class)); } }