user()->currentWorkspace->id; return [ 'content' => [ 'nullable', 'string', 'max:10000', Rule::when( $this->filled('scheduled_at'), [new ContentFitsPlatformLimits($this->resolveSelectedPlatforms($workspaceId))] ), ], ...PostMediaRules::rules(hosted: false), 'platforms' => ['required', 'array', 'min:1'], 'platforms.*.social_account_id' => [ 'required', 'uuid', Rule::exists('social_accounts', 'id') ->where('workspace_id', $workspaceId) ->where('is_active', true), ], 'platforms.*.content_type' => [ 'required', 'string', Rule::in(array_column(ContentType::cases(), 'value')), new ContentTypeMatchesPlatform, ], ...PostPlatformMetaRules::rules(), 'scheduled_at' => ['nullable', 'date', 'after:now'], 'label_ids' => ['sometimes', 'array'], 'label_ids.*' => [ 'uuid', Rule::exists('workspace_labels', 'id')->where('workspace_id', $workspaceId), ], ]; } /** * @return array */ public function messages(): array { return PostPlatformMetaRules::messages(); } /** * @return array */ public function attributes(): array { return PostPlatformMetaRules::attributes(); } /** * @return Collection */ public function selectedPlatforms(): Collection { return $this->resolveSelectedPlatforms($this->user()->currentWorkspace->id)->values(); } /** * @return Collection */ private function resolveSelectedPlatforms(string $workspaceId): Collection { $accountIds = collect($this->input('platforms', []))->pluck('social_account_id')->filter()->all(); if (empty($accountIds)) { return collect(); } return SocialAccount::query() ->where('workspace_id', $workspaceId) ->whereIn('id', $accountIds) ->pluck('platform', 'id'); } }