orox / socialposter
A social media posting package
Requires
- php: ^8.1
- illuminate/console: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
- noweh/twitter-api-v2-php: ^3.7
- saloonphp/laravel-plugin: ^3.6
Requires (Dev)
- orchestra/testbench: ^7.0 || ^8.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2025-07-15 14:11:19 UTC
README
Got it! Here’s the README without any references to testing:
Laravel SocialPoster
A flexible, extensible Laravel package to post content to multiple social media platforms (Twitter, Facebook, Instagram) using the Strategy design pattern. Easily add new platforms, support multiple accounts, and track posts with Eloquent models.
Features
- Strategy-based posting for multiple social media platforms
- Support for multi-account posting
- Polymorphic Eloquent model to track posts across platforms
- Reusable service classes to handle API communication
- Built-in Twitter integration example
- Easily extend with your own social media drivers
- Laravel-native, clean and testable design
Installation
Require the package via Composer:
composer require vendor/social-poster
Publish migrations and config:
php artisan vendor:publish --provider="Vendor\SocialPoster\SocialPosterServiceProvider" --tag="migrations" php artisan migrate php artisan vendor:publish --provider="Vendor\SocialPoster\SocialPosterServiceProvider" --tag="config"
Configuration
Edit the config file config/socialposter.php
to add your social media account credentials:
return [ 'accounts' => [ 'twitter' => [ 'default' => [ 'consumer_key' => env('TWITTER_CONSUMER_KEY'), 'consumer_secret' => env('TWITTER_CONSUMER_SECRET'), 'access_token' => env('TWITTER_ACCESS_TOKEN'), 'access_token_secret' => env('TWITTER_ACCESS_TOKEN_SECRET'), 'bearer_token' => env('TWITTER_BEARER_TOKEN'), 'account_id' => env('TWITTER_ACCOUNT_ID'), ], 'brand_2' => [ // secondary Twitter account credentials ], ], // Add Facebook, Instagram, etc. ], ];
Usage
1. Make your Eloquent models implement SocialMediaPostable
Use the provided trait and implement required methods:
use Vendor\SocialPoster\Contracts\SocialMediaPostable; use Vendor\SocialPoster\Traits\IsSocialMediaPostable; class Article extends Model implements SocialMediaPostable { use IsSocialMediaPostable; public function getSocialMediaBody(string $platform): string { return $this->title . ' - Read more at ' . $this->url; } public function getSocialMediaImage(string $platform): ?string { return $this->featured_image_path; } }
2. Use the SocialPoster
facade or service class to post
use Vendor\SocialPoster\Facades\SocialPoster; use Vendor\SocialPoster\Drivers\TwitterStrategy; SocialPoster::using(new TwitterStrategy()) ->post($article, 'default');
You can post to other platforms by creating your own Strategy classes implementing SocialMediaStrategy
.
Adding New Platforms
Create a new Strategy implementing SocialMediaStrategy
and a Service class handling API calls.
Example skeleton:
class FacebookStrategy implements SocialMediaStrategy { public function getPlatform(): string { return 'facebook'; } public function post(SocialMediaPostable $model, string $account): string { // Use your FacebookService to post content } }
Database
Your social media posts are stored in the social_media_posts
table with polymorphic relations.
The table stores:
- Platform name (Twitter, Facebook, etc.)
- Account identifier
- Polymorphic postable model reference
- Social platform's post ID
License
MIT License © Your Name or Company
Contributing
Contributions are welcome! Please open issues and pull requests on GitHub.
Support
If you find bugs or need help, open an issue on GitHub.
If you want me to generate any other docs or help with setup, just say the word!