validate((new AttachExistingAssetRequest)->rules()); $post = Post::where('workspace_id', $request->user()?->current_workspace_id) ->find(data_get($validated, 'post_id')); if (! $post) { return Response::error('Post not found.'); } if ($denied = $this->denyUnlessCan($request, 'update', $post, 'Not authorized to update this post.')) { return $denied; } if (PostStatusRules::blocksEditing($post)) { return Response::error(PostStatusRules::editBlockedMessage()); } $workspace = $request->user()?->currentWorkspace; if ($workspace === null) { return Response::error(AttachExistingAsset::ASSET_NOT_FOUND_MESSAGE); } $asset = FindWorkspaceAsset::execute($workspace, data_get($validated, 'asset_id')); if (! $asset) { return Response::error(AttachExistingAsset::ASSET_NOT_FOUND_MESSAGE); } if (! in_array($asset->type, $post->allowedMediaTypes(), true)) { return Response::error(AttachExistingAsset::UNSUPPORTED_TYPE_MESSAGE); } AttachExistingAsset::execute( $post, $asset, data_get($validated, 'alt'), ); $post->refresh()->load(['postPlatforms.socialAccount', 'labels']); return Response::structured([ 'post' => (new PostResource($post))->resolve(), ]); } public function schema(JsonSchema $schema): array { return [ 'post_id' => $schema->string()->required()->description('Required UUID of the post to update. Must belong to the current workspace and be draft or scheduled. Other workspaces return "Post not found." Published, partially published, failed, or publishing posts are rejected.'), 'asset_id' => $schema->string()->required()->description('Required UUID of an Asset Library item in the current workspace (from list-assets-tool or get-asset-tool). Missing, other-workspace, or non-library media returns "Asset not found." Type must be allowed by the post\'s enabled platforms.'), 'alt' => $schema->string()->description('Optional accessibility alt text for images (ignored for video and document). Maximum 2000 characters. When set, replaces any alt_text already on the library item. Omit to keep the library item\'s existing alt_text.'), ]; } }