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:
m105
2026-07-27 21:24:49 +03:00
parent 44f979820f
commit 90f313c134
12 changed files with 183 additions and 33 deletions
+15 -8
View File
@@ -22,7 +22,7 @@ class Index extends Component
public string $siteId = '';
public string $socialAccountId = '';
public array $selectedAccountIds = [];
public string $type = '';
@@ -42,7 +42,7 @@ class Index extends Component
public function render()
{
$posts = Post::with(['site', 'socialAccount'])->orderByDesc('created_at')->get();
$posts = Post::with(['site', 'socialAccounts'])->orderByDesc('created_at')->get();
return view('livewire.posts.index', [
'posts' => $posts,
@@ -111,10 +111,10 @@ class Index extends Component
public function edit(int $id): void
{
$post = Post::findOrFail($id);
$post = Post::with('socialAccounts')->findOrFail($id);
$this->editingId = $post->id;
$this->siteId = (string) $post->site_id;
$this->socialAccountId = $post->social_account_id ? (string) $post->social_account_id : '';
$this->selectedAccountIds = $post->socialAccounts->pluck('id')->map(fn ($id) => (string) $id)->toArray();
$this->type = $post->type;
$this->title = (string) $post->title;
$this->body = $post->body;
@@ -129,7 +129,8 @@ class Index extends Component
{
$validated = $this->validate([
'siteId' => ['required', 'integer', 'exists:sites,id'],
'socialAccountId' => ['nullable', 'integer', 'exists:social_accounts,id'],
'selectedAccountIds' => ['array'],
'selectedAccountIds.*' => ['integer', 'exists:social_accounts,id'],
'type' => ['required', 'string', 'in:' . implode(',', Post::TYPES)],
'title' => ['nullable', 'string', 'max:255'],
'body' => ['required', 'string'],
@@ -139,9 +140,8 @@ class Index extends Component
'scheduledAt' => ['nullable', 'date'],
]);
Post::updateOrCreate(['id' => $this->editingId], [
$post = Post::updateOrCreate(['id' => $this->editingId], [
'site_id' => $validated['siteId'],
'social_account_id' => $validated['socialAccountId'] ?: null,
'type' => $validated['type'],
'title' => $validated['title'] ?: null,
'body' => $validated['body'],
@@ -151,6 +151,13 @@ class Index extends Component
'scheduled_at' => $validated['scheduledAt'] ?: null,
]);
// Sync social accounts using pivot table
if ($this->editingId) {
$post->socialAccounts()->sync($validated['selectedAccountIds'] ?: []);
} else {
$post->socialAccounts()->attach($validated['selectedAccountIds'] ?: []);
}
$this->resetForm();
$this->showForm = false;
}
@@ -165,7 +172,7 @@ class Index extends Component
$this->editingId = null;
$this->templateId = null;
$this->siteId = '';
$this->socialAccountId = '';
$this->selectedAccountIds = [];
$this->type = '';
$this->title = '';
$this->body = '';