*/ public static function getModelsCached(): \Illuminate\Database\Eloquent\Collection { return Cache::remember(static::getCacheKey(), 86400, function () { $class = static::class; /** @var \Illuminate\Database\Eloquent\Model $class */ return $class::query() ->when(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 */ private static function getCacheKey(): string { return 'cache_' . str_replace('\\', '_', static::class); } }