Illuminate\Support\Manager — anatomy of the driver system
The abstract base class behind Laravel’s driver system since version 4.0. Learn how to register custom drivers, extend built-in managers, and use MultipleInstanceManager.
Illuminate\Support\Manager is an abstract class that has existed since Laravel 4.0. It provides the foundation for building systems that can switch between multiple “drivers” — cache backends, session stores, mail transports, and so on.A “driver” is a backend implementation that satisfies the same interface while using a different underlying technology. For sessions, the available drivers are file, cookie, database, and redis. The active driver is chosen by a single driver key in the configuration file.
Not every class with “Manager” in its name extends Illuminate\Support\Manager. Some provide their own equivalent implementation.
Class
Extends Manager?
Illuminate\Session\SessionManager
✅ Yes
Illuminate\Cache\CacheManager
❌ No (custom implementation)
Illuminate\Queue\QueueManager
❌ No (custom implementation)
Laravel\Socialite\SocialiteManager
✅ Yes
Classes that do not extend Manager still follow the same extend() pattern conceptually. Understanding the Manager class therefore gives you a mental model that applies across the entire framework.
Calling driver() follows this sequence:The driver name is converted to a method name using Str::studly().
// From Illuminate\Support\Manager::createDriver()protected function createDriver($driver){ if (isset($this->customCreators[$driver])) { return $this->callCustomCreator($driver); } $method = 'create'.Str::studly($driver).'Driver'; if (method_exists($this, $method)) { return $this->$method(); } throw new InvalidArgumentException("Driver [$driver] not supported.");}
So the file driver maps to createFileDriver(), and a driver named my-custom maps to createMyCustomDriver().
Pass a driver name and a closure to extend() to register a custom driver. The closure receives the container instance.
use Illuminate\Support\Facades\Session;Session::extend('redis-cluster', function ($app) { return new RedisClusterSessionHandler( $app->make('redis'), $app['config']['session'], );});
extend() binds the closure to $this (the manager), so you can access the manager’s properties and methods from inside the closure.
namespace App\Notifications;use Illuminate\Support\Manager;class NotificationManager extends Manager{ public function getDefaultDriver(): string { return $this->config->get('notifications.driver', 'slack'); } protected function createSlackDriver(): SlackNotifier { return new SlackNotifier( $this->config->get('notifications.slack'), ); } protected function createEmailDriver(): EmailNotifier { return new EmailNotifier( $this->config->get('notifications.email'), ); } protected function createLogDriver(): LogNotifier { return new LogNotifier( $this->container->make('log'), ); }}
2
Register in a service provider
namespace App\Providers;use App\Notifications\NotificationManager;use Illuminate\Support\ServiceProvider;class NotificationServiceProvider extends ServiceProvider{ public function register(): void { $this->app->singleton(NotificationManager::class, function ($app) { return new NotificationManager($app); }); }}
3
Add a custom driver at runtime
// In AppServiceProvider::boot() or a dedicated provider$manager = app(NotificationManager::class);$manager->extend('teams', function ($app) { return new TeamsNotifier( $app['config']['notifications.teams'], );});
4
Use it
$manager = app(NotificationManager::class);// Use the default driver$manager->send('Hello');// Request a specific driver$manager->driver('email')->send('Hello');// Resolved drivers are cached — same instance returned each time$manager->driver('slack');
Illuminate\Support\MultipleInstanceManager was added in Laravel 10. Where Manager manages driver types (like file or redis), MultipleInstanceManager manages named instances — multiple independently configured instances of the same logical resource.
// From the sourceabstract public function getDefaultInstance();abstract public function setDefaultInstance($name);abstract public function getInstanceConfig($name);
getInstanceConfig() must return an array that includes a driver key (or whatever key $driverKey is set to).
This example shows a manager that supports multiple independently configured SMS gateways.
namespace App\Sms;use Illuminate\Support\MultipleInstanceManager;class SmsManager extends MultipleInstanceManager{ public function getDefaultInstance(): string { return $this->config->get('sms.default', 'primary'); } public function setDefaultInstance($name): void { $this->config->set('sms.default', $name); } // Return the configuration array for a named instance public function getInstanceConfig($name): array { return $this->config->get("sms.gateways.{$name}"); } // The $config array is passed automatically by resolve() protected function createTwilioDriver(array $config): TwilioSmsGateway { return new TwilioSmsGateway( $config['account_sid'], $config['auth_token'], ); } protected function createVonageDriver(array $config): VonageSmsGateway { return new VonageSmsGateway( $config['api_key'], $config['api_secret'], ); }}
$sms = app(SmsManager::class);// Default instance (primary → twilio)$sms->send('+819012345678', 'Your code: 123456');// Select a specific instance$sms->instance('backup')->send('+819012345678', 'Your code: 123456');// Use the marketing gateway$sms->instance('marketing')->send('+819012345678', 'Campaign notice');
MultipleInstanceManager supports extend() and __call in the same way as Manager. Unknown method calls are forwarded to the default instance automatically.
// Forget a specific instance$manager->forgetInstance('backup');// Forget the default instance$manager->forgetInstance();// Forget multiple instances at once$manager->forgetInstance(['primary', 'backup']);// Unset and clear an instance$manager->purge('backup');
Manager manages driver types. Implement createXxxDriver() methods and use extend() to add new ones.
MultipleInstanceManager manages named instances. Use it when a package needs to support multiple independently configured connections.
Not every “Manager” class in Laravel extends Illuminate\Support\Manager. CacheManager and QueueManager are notable exceptions with their own implementations.
The Macroable trait
Learn how to add custom methods to existing Laravel classes using the Macroable trait.