This package makes it easy to send notifications via Twitter with Laravel 5.4

1.0.8 2018-09-10 05:55 UTC


Latest Version on Packagist Software License Build Status StyleCI SensioLabsInsight Quality Score Code Coverage Total Downloads

This package makes it easy to send notifications using Twitter with Laravel 5.3+.



You can install this package via composer:

composer require laravel-notification-channels/twitter

Next add the service provider to your config/app.php:

'providers' => [

Setting up the Twitter service

You will need to create a Twitter app in order to use this channel. Within in this app you will find the keys and access tokens. Place them inside your .env file. In order to load them, add this to your config/services.php file:

'twitter' => [
	'consumer_key'    => env('TWITTER_CONSUMER_KEY'),
	'consumer_secret' => env('TWITTER_CONSUMER_SECRET'),
	'access_token'    => env('TWITTER_ACCESS_TOKEN'),
	'access_secret'   => env('TWITTER_ACCESS_SECRET')

This will load the Twitter app data from the .env file. Make sure to use the same keys you have used there like TWITTER_CONSUMER_KEY.


Follow Laravel's documentation to add the channel to your Notification class.

Publish Twitter status update

use NotificationChannels\Twitter\TwitterChannel;
use NotificationChannels\Twitter\TwitterStatusUpdate;

class NewsWasPublished extends Notification

     * Get the notification's delivery channels.
     * @param  mixed  $notifiable
     * @return array
    public function via($notifiable)
        return [TwitterChannel::class];

    public function toTwitter($notifiable)
        return new TwitterStatusUpdate('Laravel notifications are awesome!');

Take a closer look at the TwitterStatusUpdate object. This is where the magic happens.

public function toTwitter($notifiable)
    return new TwitterStatusUpdate('Laravel notifications are awesome!');

Publish Twitter status update with images

It is possible to publish images with your status update too. You just have to pass the image path to the withImage method.

public function toTwitter($notifiable)
    return (new TwitterStatusUpdate('Laravel notifications are awesome!'))->withImage('marcel.png');

If you want to use multiple images, just pass an array of paths.

return (new TwitterStatusUpdate('Laravel notifications are awesome!'))->withImage([

Send a direct message

To send a Twitter direct message to a specific user, you will need the TwitterDirectMessage class. Provide the Twitter user handler as the first parameter and the the message as the second one.

public function toTwitter($notifiable)
     return new TwitterDirectMessage('marcelpociot', 'Hey Marcel, it was nice meeting you at the Laracon.');

Make sure the user is following you on Twitter to make this work.


Please see CHANGELOG for more information what has changed recently.


$ composer test


If you discover any security related issues, please email instead of using the issue tracker.


Please see CONTRIBUTING for details.



The MIT License (MIT). Please see License File for more information.