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/ */
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');