- How do I use Laravel Manager to create a custom payment gateway integration?
- Start by defining a `PaymentGatewayManager` class extending `Manager`. Register your drivers (e.g., Stripe, PayPal) in the `extend()` method, then inject the manager into your service. Each driver must implement `ManagerInterface` with `connect()` and `disconnect()` methods. Configuration is handled via Laravel’s config system, so no extra setup is needed.
- Does Laravel Manager work with Laravel 13 and PHP 8.5?
- Yes, Laravel Manager officially supports Laravel 8–13 and PHP 7.4–8.5. The package is regularly updated to ensure compatibility with new Laravel releases. Check the [GitHub releases](https://github.com/GrahamCampbell/Laravel-Manager/releases) for version-specific notes.
- Can I dynamically switch between drivers at runtime (e.g., failover for APIs)?
- Yes, use the `extend()` method to register drivers dynamically or switch connections via `Manager::setDriver()`. For failover logic, implement reconnection logic in your driver’s `connect()` method or use Laravel’s container to bind a fallback driver conditionally.
- How does lazy loading improve performance in high-traffic Laravel apps?
- Connections are instantiated only when first used, reducing memory overhead for unused drivers. This is ideal for multi-tenant apps (e.g., a CRM with Salesforce/HubSpot support) where only one driver is active per request. The package also pools connections to avoid redundant instantiation.
- What’s the effort to migrate an existing custom manager to Laravel Manager?
- Refactor your monolithic manager into driver classes implementing `ManagerInterface`. Update your service bindings to use the new manager pattern. Most logic (e.g., connection pooling) is handled by Laravel Manager, but driver-specific code must be rewritten. Test thoroughly, especially for edge cases like reconnection.
- Are there built-in retry mechanisms or connection health checks?
- No, Laravel Manager is a low-level abstraction. You’ll need to implement retry logic (e.g., using Laravel’s `retry()` helper) or health checks in your drivers. For observability, integrate with Laravel Horizon or Sentry to log connection failures or performance metrics.
- How do I test a driver built with Laravel Manager?
- Mock the manager’s `connect()` method in your tests to return a stubbed driver instance. Use Laravel’s `Mockery` or PHPUnit’s `createMock()` to simulate connections. Test driver-specific logic separately, then verify the manager resolves the correct driver based on configuration.
- Is Laravel Manager suitable for real-time systems (e.g., WebSockets) where connections must persist?
- While the package supports connection pooling, real-time systems may need additional logic to handle persistent connections. Avoid relying solely on Laravel’s request lifecycle for connection management. Consider using Laravel’s `app()->singleton()` to force connection reuse or implement a custom connection handler.
- Can third-party packages extend Laravel Manager with new drivers?
- Yes, third-party drivers can be registered via `extend()` or by publishing configuration. Enforce version compatibility by checking Laravel Manager’s version in your package’s `composer.json` constraints. Document your driver’s requirements clearly to avoid runtime conflicts.
- What’s the difference between Laravel Manager and Laravel’s built-in Filesystem or Queue drivers?
- Laravel Manager is a *generic* abstraction for any driver-based service (e.g., payment gateways, analytics tools), while Filesystem or Queue drivers are *specialized* for storage or job processing. Use Manager when you need interchangeable backends with custom logic; use built-in drivers for Laravel’s native integrations.