- How do I install Shariff in a Laravel project?
- Run `composer require heise/shariff` and configure it via a `config/shariff.php` file. Bind the backend to Laravel’s service container in `AppServiceProvider` and expose counts via a controller or API route.
- Does Shariff work with Laravel’s caching system?
- Yes, replace the default Laminas Cache with Laravel’s Cache facade (e.g., Redis or FileCache) by implementing a custom `CacheInterface` adapter. The package supports Laravel’s built-in caching drivers.
- Which Laravel versions support Shariff?
- Shariff requires PHP 8.1+, so it’s compatible with Laravel 10.x and 11.x. Test thoroughly if using newer PHP versions (8.3/8.4) with Laravel’s latest LTS releases.
- How do I restrict Shariff to specific domains?
- Define allowed domains in `config/shariff.php` under the `domains` key. If empty, all domains are permitted. This is useful for GDPR compliance and security.
- Can I use Shariff asynchronously for better performance?
- Yes, leverage Laravel’s queue system to refresh share counts asynchronously. Set a longer cache TTL (e.g., 5 minutes) and dispatch a job to update counts periodically.
- What happens if Facebook’s API changes or goes down?
- Shariff relies on Facebook’s Graph API (v25.0). Monitor deprecation notices and implement fallback logic (e.g., cached values or graceful degradation). Laravel’s monitoring tools like Sentry can log failures.
- Is Shariff secure for public-facing endpoints?
- The backend endpoint (`/shariff-backend`) should be rate-limited or authenticated if exposed publicly. Use Laravel’s middleware (e.g., `throttle`) to prevent abuse.
- How do I customize Shariff for additional social platforms?
- Extend the package by implementing new service classes for unsupported platforms (e.g., email shares). Follow the existing service pattern and register them in `config/shariff.php`.
- Can I deploy Shariff standalone or must it run inside Laravel?
- Shariff can run standalone (via `index.php`) or integrate into Laravel. For privacy compliance, standalone deployment may be preferable to avoid mixing analytics with app logic.
- How do I handle caching for high-traffic Laravel apps?
- Use Laravel’s Redis or Memcached drivers for distributed caching. Adjust the cache TTL based on traffic (e.g., 60s for real-time needs, 5m for batch updates). Horizontal scaling is supported if cache is external.