is_active = !$channel->is_active; $channel->save(); } public function openAccountModal(int $channelId): void { $this->managingChannelId = $channelId; } public function closeAccountModal(): void { $this->managingChannelId = null; } public function attachAccount(int $accountId): void { if (!$this->managingChannelId) { return; } $channel = PlatformChannel::findOrFail($this->managingChannelId); if (!$channel->platformAccounts()->where('platform_account_id', $accountId)->exists()) { $channel->platformAccounts()->attach($accountId, [ 'is_active' => true, 'priority' => 1, 'created_at' => now(), 'updated_at' => now(), ]); } } public function detachAccount(int $channelId, int $accountId): void { $channel = PlatformChannel::findOrFail($channelId); $channel->platformAccounts()->detach($accountId); } public function render() { $channels = PlatformChannel::with(['platformInstance', 'platformAccounts'])->orderBy('name')->get(); $allAccounts = PlatformAccount::where('is_active', true)->get(); $managingChannel = $this->managingChannelId ? PlatformChannel::with('platformAccounts')->find($this->managingChannelId) : null; $availableAccounts = $managingChannel ? $allAccounts->filter(fn($account) => !$managingChannel->platformAccounts->contains('id', $account->id)) : collect(); return view('livewire.channels', [ 'channels' => $channels, 'managingChannel' => $managingChannel, 'availableAccounts' => $availableAccounts, ])->layout('layouts.app'); } }