- How do I install the Saloon Pagination Plugin in a Laravel project?
- Run `composer require saloonphp/pagination-plugin` in your Laravel project. Ensure you’re using Saloon v3.x and Laravel 8.0+. Register the plugin in your Saloon connector’s `withPlugins()` method: `$this->withPlugins(new PaginationPlugin()).`
- Does this plugin support cursor-based pagination (e.g., GitHub, GraphQL)?
- Yes, the plugin supports cursor-based pagination out of the box. Use the `CursorPaginationStrategy` in your connector’s `paginationStrategy()` method. For non-standard cursors (e.g., base64-encoded JSON), extend `PaginationStrategy` to handle custom logic.
- Can I use this plugin with Laravel’s Scout for search pagination?
- No, this plugin is Saloon-specific and doesn’t integrate natively with Scout. For Scout pagination, use its built-in features. However, you can manually wrap the Paginator in a Laravel Job if you need to process paginated API results asynchronously.
- How does the plugin handle rate limits or API errors during pagination?
- The plugin includes configurable retry logic (e.g., `$paginator->retryOn([429, 500])`) to handle rate limits and errors. For stricter control, implement a custom `RetryStrategy` or use Saloon’s built-in retry mechanisms in your connector.
- Will this plugin work with Laravel queues for bulk operations?
- Yes, use the `chunk()` method to process paginated results in batches: `$paginator->chunk(100)->each(fn($item) => dispatch(new ProcessItemJob($item)));`. This integrates with Laravel’s queue system for async processing of large datasets.
- What Laravel versions and PHP versions are supported?
- The plugin requires Laravel 8.0+ and PHP 8.1+. For PHP 8.5+, it includes strict return types for better type safety. Always check the latest release notes for compatibility updates, as Saloon v3.x may have version-specific dependencies.
- How do I test paginated API responses in my Laravel tests?
- Use Saloon’s `MockConnector` to simulate paginated responses. Mock the `Response` object with multi-page JSON data and verify the Paginator processes all pages correctly. Example: `$mock->shouldReceive('json')->andReturn($multiPageResponse).`
- What’s the best way to cache paginated API responses in Laravel?
- Leverage Laravel’s Cache facade via the `cacheFor()` method: `$paginator->cacheFor(3600)`. This reduces redundant API calls for static or slowly changing data. For dynamic data, combine caching with TTL (time-to-live) settings.
- Can I use this plugin if I’m not using Saloon for other HTTP requests?
- No, this plugin is tightly coupled to Saloon’s request/response cycle. If you’re not using Saloon, consider alternatives like Guzzle’s middleware or Symfony’s HTTP Client with custom pagination logic. Migrating existing connectors may require significant refactoring.
- How do I handle infinite loops or malformed pagination responses?
- The plugin includes loop detection and error handling by default. For edge cases, configure custom strategies: disable loop detection with `$paginator->disableLoopDetection()` (use cautiously) or implement a `PaginationStrategy` to validate responses before processing.