-
app/Jobs/TweetStreamIsLiveJob.php
Open in GitHubuse App\Models\Stream; use App\Services\Twitter; class TweetStreamIsLiveJob { public function __construct( public Stream $stream, ) {} public function handle(): void { // app(Twitter::class) ->tweet("? A new stream just started: {$this->stream->title}".PHP_EOL.$this->stream->url()); } }
-
app/Services/Twitter.php
Open in GitHubuse Abraham\TwitterOAuth\TwitterOAuth; class Twitter { protected TwitterOAuth $twitter; public function __construct(TwitterOAuth $twitter) { $this->twitter = $twitter; } public function tweet(string $status) { if (! app()->environment('production')) { return; } return (array) $this->twitter->post('statuses/update', compact('status')); } }
-
composer.json
Open in GitHub{ "require": { "php": "^8.0", "abraham/twitteroauth": "^2.0", // }, }