Add Cross-Posting support for multiple social accounts
- Create post_social_account pivot table for many-to-many relationship - Add migration to migrate existing social_account_id to pivot table - Remove social_account_id column from posts table - Update Post model with socialAccounts() BelongsToMany relationship - Update Posts Livewire component to use array of selectedAccountIds - Update Posts view with checkboxes for selecting multiple accounts - Update PublishPostJob to iterate through all social accounts of matching type - Update Publisher interface to accept optional SocialAccount parameter - Update all Publishers (WordPress, Reddit, Twitter, LinkedIn) to support cross-posting - Display multiple social accounts as badges in posts table Now a single post can be published to multiple social accounts of the same type. For example: a Twitter post can be published to multiple Twitter accounts. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -13,13 +13,14 @@ class LinkedInPublisher implements Publisher
|
||||
return $post->type === 'linkedin';
|
||||
}
|
||||
|
||||
public function publish(Post $post): PublishResult
|
||||
public function publish(Post $post, ?SocialAccount $socialAccount = null): PublishResult
|
||||
{
|
||||
if (! $post->body) {
|
||||
return PublishResult::rejected("Post {$post->id} has no body, required for a LinkedIn post.");
|
||||
}
|
||||
|
||||
$account = $post->socialAccount;
|
||||
// Use the passed social account, or fall back to the first linked one
|
||||
$account = $socialAccount ?: $post->socialAccounts->first();
|
||||
|
||||
if (! $account || $account->network !== 'linkedin') {
|
||||
return PublishResult::rejected("Post {$post->id} has no linked LinkedIn social account.");
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Support\Publishing;
|
||||
|
||||
use App\Models\Post;
|
||||
use App\Models\SocialAccount;
|
||||
|
||||
interface Publisher
|
||||
{
|
||||
@@ -12,5 +13,5 @@ interface Publisher
|
||||
*/
|
||||
public function supports(Post $post): bool;
|
||||
|
||||
public function publish(Post $post): PublishResult;
|
||||
public function publish(Post $post, ?SocialAccount $socialAccount = null): PublishResult;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class RedditPublisher implements Publisher
|
||||
return $post->type === 'reddit';
|
||||
}
|
||||
|
||||
public function publish(Post $post): PublishResult
|
||||
public function publish(Post $post, ?SocialAccount $socialAccount = null): PublishResult
|
||||
{
|
||||
if (! $post->title) {
|
||||
return PublishResult::rejected("Post {$post->id} has no title, required for a Reddit post.");
|
||||
@@ -23,7 +23,8 @@ class RedditPublisher implements Publisher
|
||||
return PublishResult::rejected("Post {$post->id} has no target subreddit set.");
|
||||
}
|
||||
|
||||
$account = $post->socialAccount;
|
||||
// Use the passed social account, or fall back to the first linked one
|
||||
$account = $socialAccount ?: $post->socialAccounts->first();
|
||||
|
||||
if (! $account || $account->network !== 'reddit') {
|
||||
return PublishResult::rejected("Post {$post->id} has no linked Reddit social account.");
|
||||
|
||||
@@ -13,13 +13,14 @@ class TwitterPublisher implements Publisher
|
||||
return $post->type === 'twitter';
|
||||
}
|
||||
|
||||
public function publish(Post $post): PublishResult
|
||||
public function publish(Post $post, ?SocialAccount $socialAccount = null): PublishResult
|
||||
{
|
||||
if (! $post->body) {
|
||||
return PublishResult::rejected("Post {$post->id} has no body, required for a Twitter post.");
|
||||
}
|
||||
|
||||
$account = $post->socialAccount;
|
||||
// Use the passed social account, or fall back to the first linked one
|
||||
$account = $socialAccount ?: $post->socialAccounts->first();
|
||||
|
||||
if (! $account || $account->network !== 'twitter') {
|
||||
return PublishResult::rejected("Post {$post->id} has no linked Twitter social account.");
|
||||
|
||||
@@ -14,7 +14,7 @@ class WordPressPublisher implements Publisher
|
||||
return $post->type === 'blog';
|
||||
}
|
||||
|
||||
public function publish(Post $post): PublishResult
|
||||
public function publish(Post $post, ?SocialAccount $socialAccount = null): PublishResult
|
||||
{
|
||||
if (! $post->title) {
|
||||
return PublishResult::rejected("Post {$post->id} has no title, required to publish to WordPress.");
|
||||
|
||||
Reference in New Issue
Block a user