- How do I integrate this DocRaptor package into a Laravel 9+ project?
- First, replace the package’s HTTP client with Laravel’s built-in `Http` facade for consistency. Bind the `Client` to Laravel’s service container in `AppServiceProvider` using `singleton()` or `bind()`, then inject it into controllers or services. Ensure your `.env` contains `DOCRAPTOR_API_KEY` and `DOCRAPTOR_TEST_MODE=true` for test environments.
- Does this package support asynchronous PDF/Excel generation for Laravel Queues?
- Yes, you can wrap DocRaptor conversions in a `ShouldQueue` job (e.g., `DocRaptorJob`) to process documents asynchronously. Use Laravel’s queue system to handle large batches or improve performance during peak times. The package’s `convert()` method can be called within the job’s `handle()` method.
- Is this package compatible with Laravel’s filesystem (local/S3) for storing generated PDFs/Excel files?
- Yes, you can save generated files to Laravel’s filesystem by using the `Storage` facade. For example, `Storage::put('documents/report.pdf', $pdf->getContent())` will store the file locally or in S3, depending on your configuration. Stream files directly to users using Laravel’s `Response` class if needed.
- What Laravel versions and PHP versions does this package support?
- The package requires PHP 5.3.2, but Laravel 9+ requires PHP 8.1+. Due to the package’s outdated PHP 5 syntax, you’ll need to fork and modernize it for Laravel 9+ compatibility. Alternatively, consider using DocRaptor’s official SDK or a maintained alternative like `spatie/pdf-to-html` for better support.
- How do I handle API errors or exceptions in Laravel with this package?
- The package throws `DocraptorException`, but it lacks Laravel-specific exception handling. Extend `RuntimeException` to create a custom `DocRaptorException` for better integration with Laravel’s error handling. Log exceptions using Laravel’s `Log` facade or integrate with monitoring tools like Sentry for production debugging.
- Can I use this package for batch processing or large HTML payloads?
- The package supports individual conversions, but batch processing would require wrapping calls in a Laravel job or queue. For large HTML payloads, ensure your server has sufficient memory and consider chunking HTML content or using Laravel’s queue system to distribute the load. Test performance with your specific payload sizes.
- Is there a way to rotate API keys or use OAuth with this package?
- The package does not natively support API key rotation or OAuth. Store your API key in Laravel’s `.env` file and update it manually when rotated. For OAuth, you’d need to extend the `Client` class to include OAuth logic, though DocRaptor’s API may not support OAuth directly. Always use environment variables for sensitive credentials.
- Are there actively maintained alternatives for Laravel that offer similar functionality?
- Yes, consider `spatie/pdf-to-html` or `barryvdh/laravel-dompdf` for PDF generation, or DocRaptor’s official PHP SDK if available. These alternatives are more likely to be maintained and compatible with modern Laravel versions. Evaluate their features (e.g., HTML-to-Excel support) to match your project’s needs.
- How do I test this package in a Laravel application?
- Use Laravel’s `Http` facade to mock API responses in tests. Create integration tests to verify PDF/Excel generation, error handling, and file storage. Test both synchronous and asynchronous workflows, including queue jobs. Ensure your test environment uses `DOCRAPTOR_TEST_MODE=true` to avoid real API calls.
- Can I use this package for production without forking it first?
- No, the package is unmaintained and uses PHP 5.3 syntax, which is incompatible with Laravel 9+. You must fork the repository, update the PHP version, and modernize the codebase (e.g., replace cURL with Laravel’s `Http` client, add PSR-15 support). Alternatively, migrate to a maintained alternative to avoid technical debt.