PHP code example of alexhackney / laravel-socialbu
1. Go to this page and download the library: Download alexhackney/laravel-socialbu 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/ */
alexhackney / laravel-socialbu example snippets
use Hei\SocialBu\Facades\SocialBu;
// Text post to all configured accounts
SocialBu::publish('Hello world!');
// With an image
SocialBu::publish('Check this out!', '/path/to/image.jpg');
SocialBu::create()
->content('Big announcement!')
->media('/path/to/image.jpg')
->media('https://example.com/video.mp4')
->to(123, 456)
->scheduledAt('2025-06-15 14:00:00')
->send();
// Save as draft
SocialBu::create()
->content('Work in progress')
->asDraft()
->send();
// Validate without sending
$payload = SocialBu::create()
->content('Test post')
->dryRun();
use Hei\SocialBu\Events\PostStatusChanged;
use Hei\SocialBu\Events\AccountStatusChanged;
// In a listener
public function handle(PostStatusChanged $event): void
{
$event->postId;
$event->accountId;
$event->status; // 'published', 'failed', etc.
$event->payload; // full webhook data
}
use Hei\SocialBu\Testing\FakeSocialBu;
test('it shares to social media', function () {
$fake = FakeSocialBu::fake();
// ... your application code that calls SocialBu ...
$fake->assertPublished('Hello!');
$fake->assertPublishedCount(1);
$fake->assertPublishedTo([123, 456]);
$fake->assertUploaded('/path/to/image.jpg');
$fake->assertUploadedCount(1);
$fake->assertNothingPublished();
});
use Hei\SocialBu\Exceptions\PostCreationException;
test('it handles publish failures', function () {
$fake = FakeSocialBu::fake()
->throwOnPublish(new PostCreationException('API down'));
// ... test your error handling ...
});