PHP code example of laravel-notification-channels / twitter

1. Go to this page and download the library: Download laravel-notification-channels/twitter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

laravel-notification-channels / twitter example snippets


...
'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')
]
...



use Illuminate\Notifications\Notification;
use NotificationChannels\Twitter\TwitterChannel;
use NotificationChannels\Twitter\TwitterMessage;
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(mixed $notifiable): TwitterMessage
    {
        return new TwitterStatusUpdate('Laravel notifications are awesome!');
    }
}

public function toTwitter(mixed $notifiable): TwitterMessage
{
    return new TwitterStatusUpdate('Laravel notifications are awesome!');
}

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

return (new TwitterStatusUpdate('Laravel notifications are awesome!'))->withImage([
    public_path('marcel.png'),
    public_path('mohamed.png')
]);

public function toTwitter(mixed $notifiable): TwitterMessage
{
    return (new TwitterStatusUpdate('Laravel notifications are awesome!'))->withVideo('video.mp4');
}

return (new TwitterStatusUpdate('Laravel notifications are awesome!'))->withVideo([
    public_path('video1.mp4'),
    public_path('video.gif')
]);

return (new TwitterStatusUpdate('Laravel notifications are awesome!'))->withVideo([
    public_path('video1.mp4'),
    public_path('video.gif')
])->withImage([
    public_path('marcel.png'),
    public_path('mohamed.png')
]);

public function toTwitter(mixed $notifiable): TwitterMessage
{
    return (new TwitterStatusUpdate('@christophrumpel Laravel notifications are awesome!'))->inReplyTo(123);
}

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

public function toTwitter(mixed $notifiable): TwitterMessage
{
     return new TwitterDirectMessage(12345, 'Hey Marcel, it was nice meeting you at the Laracon.');
}

public function routeNotificationForTwitter($notification)
{
   return [
      'TWITTER_CONSUMER_KEY',
      'TWITTER_CONSUMER_SECRET',
      'TWITTER_ACCESS_TOKEN',
      'TWITTER_ACCESS_SECRET',
   ];
}