- How do I install and configure Cloudinary in Laravel using this package?
- Run `composer require cloudinary-labs/cloudinary-laravel`, then execute `php artisan cloudinary:install` to generate the config file. Add your Cloudinary API key, cloud name, and upload preset in `.env`. The package auto-registers the service provider and facade, so no manual bootstrapping is needed.
- Does this package support async uploads via Laravel queues?
- Yes, the package integrates with Laravel’s queue system. Use `Cloudinary::upload($file, 'queue')->wait()` for async processing. Configure your queue driver (e.g., database, Redis) in Laravel’s `.env` and ensure the `cloudinary` queue is processed by your queue worker.
- Can I use Cloudinary’s AI features (e.g., auto-tagging, generative fill) with this package?
- Absolutely. The package exposes Cloudinary’s AI methods directly. For example, use `Cloudinary::autoTag($publicId)` for auto-tagging or `Cloudinary::generateFill($publicId, $prompt)` for generative fill. Check Cloudinary’s [AI documentation](https://cloudinary.com/documentation/ai) for available features.
- What Laravel versions does this package support, and how do I check compatibility?
- The package officially supports Laravel 11+. For older versions (e.g., Laravel 8/9/10), check the `composer.json` for backported branches or pin a specific version. Test thoroughly in staging, as some features (e.g., async uploads) may rely on newer Laravel queue improvements.
- How do I handle signed URLs for private media in production?
- Use `Cloudinary::image($publicId)->signed()` or `Cloudinary::video($publicId)->signed()` to generate time-limited URLs. Configure the `cloudinary.signed_url_expiration` in your `.env` (default: 3600 seconds). For dynamic signed URLs, cache them in Laravel’s cache layer to reduce Cloudinary API calls.
- Can I integrate Cloudinary with Eloquent models for media attachments?
- Yes, the package provides a `HasMedia` trait for Eloquent models. Use `Cloudinary::attach($model, $file)` to upload and link media to a model. The package stores metadata (e.g., `public_id`) in a `media` pivot table by default, but you can customize this in the config.
- What’s the best way to optimize costs for high-volume media processing?
- Monitor Cloudinary’s usage dashboard to track API calls and bandwidth. Cache transformed URLs in Laravel’s cache or CDN (e.g., Varnish). Use eager transformations (e.g., `Cloudinary::image()->resize(500)->delivery()`) to avoid repeated API calls. Set `cloudinary.max_file_size` in config to reject oversized uploads early.
- How do I handle Cloudinary outages or fallback to local storage?
- Implement a hybrid strategy: store `public_id` in your DB and use Laravel’s filesystem (e.g., S3) as a temporary fallback. Extend the `MediaServiceContract` to add local storage logic. For critical apps, add retry logic in Laravel queues for failed Cloudinary operations and log fallbacks for debugging.
- Are there Blade components for displaying Cloudinary media with transformations?
- Yes, the package includes Blade components like `@cloudinary` for easy image/video rendering. Example: `@cloudinary($media->public_id, ['width' => 500, 'crop' => 'fill'])` generates a transformed URL. Customize the component in `resources/views/vendor/cloudinary/`.
- What alternatives exist if I need more control over Cloudinary’s API?
- For advanced use cases, consider the official [Cloudinary PHP SDK](https://github.com/cloudinary/cloudinary_php) or build a custom service layer wrapping the SDK. This package abstracts common operations (e.g., uploads, transformations) but may lack niche features. Review the [Cloudinary API docs](https://cloudinary.com/documentation/php_integration) for unsupported methods.