- How do I install the Laravel Forge SDK?
- Install it with Composer by running composer require laravel/forge-sdk. Check the package's PHP and Laravel version constraints on Packagist before adding it to an existing application. You then instantiate Laravel\Forge\Forge with a Forge API token and resolve an organization slug before calling endpoints.
- Do all Laravel Forge SDK v4 calls require an organization slug?
- Yes. Version 4 targets Forge API v2 and every endpoint now requires an organization slug as the first parameter. Resolve it once with organizations() and persist the slug in configuration so workflows do not rediscover it on every call.
- How do I authenticate Laravel Forge SDK requests?
- Create a Forge instance with new Laravel\Forge\Forge($apiToken), passing a Forge API token. Store the token in environment variables or a secret manager and never commit it to source control. Validate that the token has access to the organization you intend to manage before running automation.
- How do I upgrade from laravel/forge-sdk v3 to v4?
- Treat v3 to v4 as an API migration, not a routine package bump. Review UPGRADE-4.0.md, add organization-slug resolution, and update every endpoint signature. Test read-only endpoints first and run old and new paths in parallel behind a feature flag if existing automation is business-critical.
- How do I handle pagination with the Laravel Forge SDK?
- Collection methods such as servers(), sites(), and recipes() return a Laravel\Forge\CursorPaginator. Use lazy() to walk every page for full enumeration, and use toArray() only when you need a bounded snapshot of the current page.
- Can I use the Laravel Forge SDK in queued jobs and Artisan commands?
- Yes, queued jobs and Artisan commands are good fits for Forge SDK automation because provisioning and deployment calls can wait on Forge-side completion. Keep SDK calls out of synchronous customer-facing request paths. Set explicit timeouts with setTimeout() and design operations to be idempotent.
- What happens when a Laravel Forge SDK operation times out?
- The SDK can throw Laravel\Forge\Exceptions\TimeoutException while waiting on an asynchronous Forge operation. The remote action may already have started or completed even though the client timed out. Reconcile state by querying Forge before retrying, and make retries idempotent to avoid duplicate resources.
- Is laravel/forge-sdk safe for destructive actions like deleting servers?
- The SDK exposes destructive calls such as deleteServer, deleteSite, and deleteDatabase, so it should not be handed to untrusted code or exposed directly to end users. Wrap it in an internal adapter that enforces approval, audit logging, and token scopes. Test destructive workflows against non-production organizations first.
- Which PHP and Laravel versions does laravel/forge-sdk support?
- Check the package's composer.json and Packagist page for the current PHP and Laravel version constraints before adoption. Pin the major version in composer.json and review changelogs before upgrades. The SDK targets Forge API v2 only, so confirm Forge account and organization configuration early.
- How should I test code that uses the Laravel Forge SDK?
- Isolate SDK usage behind a service class or adapter so application code depends on your interface rather than SDK resource shapes. Inject a fake or stub implementation in unit tests and avoid calling the live Forge API in normal test suites. Use a dedicated Forge organization for contract or integration tests, starting with read-only endpoints.