Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Dashboard Twitter Tile Laravel Package

spatie/laravel-dashboard-twitter-tile

Laravel Dashboard tile that shows recent Twitter mentions. Built for Spatie’s laravel-dashboard, with configurable polling and display so you can surface who’s talking about your brand right on your internal dashboard.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require spatie/laravel-dashboard-twitter-tile
    

    Publish the config file (if needed):

    php artisan vendor:publish --provider="Spatie\DashboardTwitterTile\DashboardTwitterTileServiceProvider"
    
  2. Configuration Edit config/dashboard-twitter-tile.php to set:

    • Your Twitter API credentials (via Twitter Developer Portal)
    • Default query terms (e.g., @yourhandle)
    • Refresh interval (default: 300 seconds)
  3. First Use Case Add the tile to your dashboard in app/Providers/DashboardServiceProvider.php:

    use Spatie\DashboardTwitterTile\DashboardTwitterTile;
    
    public function boot()
    {
        Dashboard::create()
            ->row()
                ->tile(DashboardTwitterTile::class);
    }
    

    Visit /dashboard to see live Twitter mentions.


Implementation Patterns

Core Workflows

  1. Dynamic Querying Override the default query terms via the tile constructor:

    DashboardTwitterTile::make()
        ->query('@customhandle OR #hashtag')
        ->maxResults(5)
    
  2. Caching & Performance Leverage Laravel’s cache for API rate limits:

    // In config/dashboard-twitter-tile.php
    'cache_key' => 'twitter_mentions_cache',
    'cache_ttl' => 60, // seconds
    
  3. Integration with Laravel Dashboard Combine with other tiles for a unified dashboard:

    Dashboard::create()
        ->row()
            ->tile(DashboardTwitterTile::class)
            ->tile(DashboardStatsTile::class)
        ->row();
    
  4. Customizing Display Extend the tile’s view (resources/views/vendor/dashboard-twitter-tile/tile.blade.php) to modify:

    • Layout (e.g., add avatars, timestamps).
    • Styling (use Tailwind classes or custom CSS).
  5. Scheduled Refreshes Use Laravel’s scheduler to pre-fetch data:

    // app/Console/Kernel.php
    $schedule->command('dashboard:refresh-twitter-tile')->everyMinute();
    

    (Requires adding a custom Artisan command.)


Gotchas and Tips

Common Pitfalls

  1. API Rate Limits

    • Twitter’s API has strict rate limits (e.g., 900 requests/15-min for v2).
    • Fix: Cache responses aggressively or use a queue (spatie/laravel-queueable-side-effects).
    • Tip: Monitor limits via Twitter API Status.
  2. Authentication Issues

    • Ensure BEARER_TOKEN in config is correct and has read permissions.
    • Debug: Test the token manually:
      curl -X GET "https://api.twitter.com/2/tweets/search/recent?query=@yourhandle" -H "Authorization: Bearer YOUR_TOKEN"
      
  3. Deprecated API Endpoints

    • The package uses Twitter API v2. If migrating from v1, update the endpoint in config:
      'endpoint' => 'https://api.twitter.com/2/tweets/search/recent',
      
  4. Empty Results

    • If no mentions appear, verify:
      • The query terms match active tweets (e.g., @yourhandle vs. #hashtag).
      • The Twitter account isn’t private or suspended.

Pro Tips

  1. Error Handling Wrap the tile in a try-catch to show user-friendly messages:

    try {
        return DashboardTwitterTile::make()->render();
    } catch (\Exception $e) {
        return view('dashboard-twitter-tile::errors.generic', ['error' => $e->getMessage()]);
    }
    
  2. Local Development Use tweetinvi for mocking Twitter responses in tests:

    // tests/TestCase.php
    use Tweetinvi\Mock\MockClient;
    
    protected function getTwitterClient()
    {
        return new MockClient('mock_token');
    }
    
  3. Extending Functionality

    • Add Filters: Override getQuery() to dynamically filter tweets (e.g., by language):
      public function getQuery()
      {
          return parent::getQuery() . ' lang:en';
      }
      
    • Custom Data: Fetch additional fields (e.g., public_metrics) by modifying the API request in getTweets().
  4. Environment-Specific Config Use Laravel’s config caching to avoid hardcoding secrets:

    // .env
    TWITTER_BEARER_TOKEN=your_token_here
    

    Then reference it in config:

    'bearer_token' => env('TWITTER_BEARER_TOKEN'),
    
  5. Testing

    • Use spatie/laravel-test-factories to mock Twitter responses:
      // tests/Feature/DashboardTwitterTileTest.php
      public function test_tile_displays_mentions()
      {
          $this->mock(TwitterClient::class, function ($mock) {
              $mock->shouldReceive('searchTweets')
                   ->once()
                   ->andReturn(['data' => [/* mock tweets */]]);
          });
      }
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport