- How do I install and configure `forest-lynx/laravel-dadata` in my Laravel project?
- Run `composer require forest-lynx/laravel-dadata`, then add your DaData API key to `.env` under `DADATA_API_KEY`. The package auto-registers a service provider, so no additional bootstrapping is needed. Keys are securely managed via Laravel’s environment variables.
- Which Laravel versions does this package support?
- The package is officially tested with Laravel 9 and 10. Check the `composer.json` constraints for exact version requirements. It requires PHP 8.0+ and follows Laravel’s dependency injection patterns for seamless integration.
- Can I use this package for address autocomplete in a frontend form?
- Yes. Call `Dadata::suggest($query)` in your controller or API endpoint to fetch suggestions, then return the JSON response to your frontend (e.g., Vue, React, or Livewire). Example: `$suggestions = Dadata::suggest(request('query'));`
- Does this package support address validation for Eloquent models?
- Yes. Use Eloquent observers to validate addresses on model save. For example, attach an observer to your `Address` model to run `Dadata::clean($address)` before saving. You can also create a custom validation rule like `DadataValid` for form requests.
- How do I handle DaData API rate limits or outages?
- The package doesn’t include built-in retry logic, so you may need to implement caching (e.g., Redis) or queue delayed requests (e.g., Laravel Queues) to avoid throttling. For outages, consider falling back to cached responses or graceful degradation with user feedback.
- Is this package limited to Russian addresses, or can it work with other regions?
- The package is primarily designed for Russian addresses via DaData’s API. For multi-region support, you’d need to integrate additional geocoding APIs (e.g., Google Maps, OpenStreetMap) alongside this package, possibly using a facade pattern to switch providers dynamically.
- Can I use this package for geocoding addresses into latitude/longitude?
- Yes. Use `Dadata::clean($address)` to parse and normalize addresses, which often includes structured data like coordinates. Store these in your database for mapping tools (e.g., Leaflet.js or Google Maps). Example: `$cleaned = Dadata::clean('ул. Ленина, 10');`
- How do I test this package in my CI/CD pipeline?
- The package lacks built-in PHPUnit tests, so you’ll need to mock DaData API responses using tools like `mockery/mockery` or `pestphp/pest`. Test edge cases like invalid addresses, rate limits, and API failures to ensure robustness in your application.
- Does this package work with Laravel’s validation system?
- Yes. You can extend Laravel’s validation rules to include DaData checks. For example, create a custom rule like `DadataValid` that uses `Dadata::clean()` or `Dadata::validate()` to ensure addresses meet your business logic before submission.
- Are there alternatives to this package for DaData integration in Laravel?
- While this package is the most Laravel-native solution for DaData, you could alternatively use a generic HTTP client like Guzzle with manual API key management. However, `forest-lynx/laravel-dadata` provides Laravel-specific conveniences like facades, Eloquent integration, and configuration-driven setup.