Singleton
Register a class as a singleton in the container
Description: Registers the class as a singleton in the container โ shared across the entire application lifecycle.
Namespace: Illuminate\Container\Attributes\Singleton
Added in: Laravel 12.21
Usage
use Illuminate\Container\Attributes\Singleton;
// Before (service provider):
$this->app->singleton(ConfigCache::class);
use Illuminate\Container\Attributes\Singleton;
// After:
#[Singleton]
class ConfigCache
{
private array $cache = [];
public function remember(string $key, callable $callback): mixed
{
return $this->cache[$key] ??= $callback();
}
}