PHP code example of siberfx / social-autopost

1. Go to this page and download the library: Download siberfx/social-autopost 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/ */

    

siberfx / social-autopost example snippets


// app/Providers/AppServiceProvider.php → boot()
Gate::define('manage-social-autopost', fn (User $user) => $user->is_admin);

use Siberfx\SocialAutopost\Concerns\PostsToSocial;
use Siberfx\SocialAutopost\Contracts\ShareableOnSocial;
use Siberfx\SocialAutopost\Posts\LinkPost;

class Article extends Model implements ShareableOnSocial
{
    use PostsToSocial;

    public function isLiveForSocial(): bool
    {
        return $this->status === 'published';
    }

    public function toSocialPost(): LinkPost
    {
        return LinkPost::make(route('blog.show', $this), $this->title)
            ->description(Str::limit(strip_tags($this->body), 250))
            ->commentary("New on the blog: {title}\n\n{url}");
    }
}

public function toSocialPost(): LinkPost
{
    return LinkPost::make(route('blog.show', $this), $this->title)
        ->commentary("New on the blog: {title}\n\n{url}")
        ->image($this->cover_url)
        ->on('x', fn (LinkPost $post) => $post->commentary('{title} {url} #laravel'))
        ->on(['instagram', 'tiktok'], fn (LinkPost $post) => $post->commentary($this->caption));
}

use Siberfx\SocialAutopost\Facades\Social;

Social::enabled();                  // collect(['linkedin', 'facebook'])
Social::isEnabled('x');             // false
Social::isConnected('linkedin');    // true when a connection is stored (no network call)

Social::share($article);            // every enabled, connected network; one record per network
Social::share($article, 'x');       // only X; rethrows if X refuses
Social::queue($article, 'facebook');
Social::wasPosted($article, 'linkedin');

public function toSocialPost(): LinkPost
{
    return LinkPost::make(route('blog.show', $this), $this->title)
        ->commentary("{title}\n\nRead more: {url}")
        ->image($this->cover_url)        // see the table: what each network does with it
        ->video($this->clip_url);        // used instead of the image where video is supported
}

Social::isConnected('x');
Social::connection('x')->name;      // the account name, from the network
Social::disconnect('x');            // revokes at the network, then forgets it

use Siberfx\SocialAutopost\Facades\Social;

Social::pages('facebook');                         // list<Page>: id, type, name, picture
Social::selectedPages('facebook');                 // ['1234567']
Social::selectPages('facebook', ['1234567', '7654321']);

Social::share($post, 'facebook');                  // one SharedPost per selected Page
Social::shareToPages($post, 'linkedin', ['urn:li:organization:1042']);   // these pages, this once
Social::wasPosted($post, 'linkedin', 'urn:li:organization:1042');

Route::view('/admin/social', 'social.connections')
    ->middleware(['auth', 'can:manage-social-autopost'])->name('social.connections');

// config/social-autopost.php
'routes' => ['after_connect' => '/admin/social', /* … */],

use Inertia\Inertia;
use Siberfx\SocialAutopost\Support\SocialProps;

Route::middleware(['auth', 'can:manage-social-autopost'])->group(function () {
    Route::get('/admin/social', fn () => Inertia::render('SocialConnections', [
        'connections' => SocialProps::connections(),   // one card per enabled network
        'flash' => SocialProps::flash(),               // the message after connecting
    ]));

    Route::get('/admin/posts/{post}', fn (Post $post) => Inertia::render('Posts/Show', [
        'post' => $post,
        'share' => SocialProps::share($post),               // every enabled, connected network
        'shareOnTikTok' => SocialProps::share($post, 'tiktok'),
    ]));
});

// config/social-autopost.php → networks.x (X's free tier allows 17 posts a day)
'rate_limit' => ['posts' => 17, 'per_seconds' => 86400],

Social::shareAt($article, now()->addDay()->setTime(9, 0), 'linkedin');
Social::shareAt($article, $campaign->starts_at);   // every enabled, connected network

use Siberfx\SocialAutopost\Models\SharedPost;

Schedule::command('model:prune', ['--model' => SharedPost::class])->daily();

'pinterest' => [
    'enabled' => (bool) env('PINTEREST_ENABLED', false),
    'autopost' => (bool) env('PINTEREST_AUTOPOST', false),
    'class' => App\Social\PinterestNetwork::class,
    'post_url' => 'https://www.pinterest.com/pin/{id}/',
    'brand' => ['color' => '#E60023'],
],
bash
composer social:install --theme=tailwind
php artisan migrate
bash
php artisan vendor:publish --tag=social-autopost-migrations
php artisan migrate
bash
php artisan social:page                        # standalone page, configured theme
php artisan social:page --layout=layouts.app   # inside your layout's @section('content')
php artisan social:page --livewire --theme=bootstrap --view=admin.social
bash
php artisan queue:work --queue=default
bash
php artisan vendor:publish --tag=social-autopost-lang
# then translate lang/vendor/social-autopost/{locale}/messages.php