- How do I add the Twitter tile to my existing Laravel dashboard?
- First, ensure you have `spatie/laravel-dashboard` installed. Then run `composer require spatie/laravel-dashboard-twitter-tile`, publish the config if needed, and register the tile in your `DashboardServiceProvider` using `Dashboard::create()->withTile(TwitterTile::class)`. Follow the [official docs](https://docs.spatie.be/laravel-dashboard) for step-by-step guidance.
- What Laravel and PHP versions does this package support?
- The package is tested with Laravel 8, 9, and 10 and requires PHP 8.0+. If you’re using Laravel 7 or PHP 7.x, compatibility isn’t guaranteed, and you may need adjustments. Always check the `composer.json` for the latest requirements.
- Do I need a Twitter Developer account to use this tile?
- Yes, you’ll need a Twitter Developer account to obtain API keys (v2 or v1.1). Store your credentials in `.env` using `TWITTER_API_KEY`, `TWITTER_API_SECRET`, `TWITTER_ACCESS_TOKEN`, and `TWITTER_ACCESS_TOKEN_SECRET`. The free tier limits you to 50k tweets/month, so plan accordingly for higher usage.
- How can I customize the Twitter tile’s appearance or functionality?
- Override the Blade templates in `resources/views/vendor/dashboard-twitter-tile` to modify styling. Extend the `TwitterTile` class to tweak query logic (e.g., search terms or time ranges). For deeper customization, review the [source code](https://github.com/spatie/laravel-dashboard-twitter-tile) or fork the package.
- What happens if the Twitter API fails or returns empty results?
- The tile includes basic error handling, but you may want to enhance it. Log API errors centrally (e.g., Sentry) and display user-friendly messages like ‘Twitter service unavailable.’ For empty results, consider adding a fallback (e.g., a static message or cached data) to avoid blank tiles.
- Can I use this tile for multiple Twitter accounts or handles?
- Yes, configure the tile to fetch mentions for specific handles (e.g., `@company_handle`) by extending the `TwitterTile` class or passing custom query parameters. If you need user-specific tiles, dynamically set the search term based on authenticated users or roles.
- How do I cache Twitter API responses to reduce rate limits?
- Use Laravel’s built-in cache or `spatie/laravel-caching` to store responses. Invalidate the cache when new data is needed (e.g., via a cron job or manual trigger). Example: `Cache::put('twitter_mentions', $response, now()->addMinutes(15));`. Balance cache duration with real-time needs.
- Are there alternatives to this package for Laravel dashboards?
- If you need social media integration, consider `spatie/laravel-activitylog` for activity tracking or build a custom tile using the Twitter API directly. For other platforms, explore `spatie/laravel-newsletter` (for email) or third-party services like Zapier. This package is specialized for Twitter mentions in Spatie’s dashboard ecosystem.
- Will this tile work with Laravel’s queue system for async Twitter API calls?
- No, the tile is designed for synchronous API calls. To offload Twitter API requests, wrap the logic in a job (e.g., `spatie/laravel-queueable`) and cache the results. Example: Dispatch a `FetchTwitterMentionsJob` and cache the output until the next refresh.
- How do I test this tile locally before deploying to production?
- Mock the Twitter API responses using tools like [Vespa](https://github.com/orchestral/testbench) or [Laravel’s HTTP testing](https://laravel.com/docs/testing#http-tests). Test edge cases like empty results, API errors, and rate limits. Run `composer test` to verify the package’s core functionality, then add your own tests for customizations.