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