tonysm/rich-text-laravel/developing-new-attachables
Claude Code and agent skill by tonysm/rich-text-laravel
- community
Checking that the SKILL.md file is still in the repository.
Turn Eloquent models into rich text content attachments (e.g., user mentions, embedded resources) using the AttachableContract and Attachable trait.
Install
npx vskill@latest install tonysm/rich-text-laravel/developing-new-attachablesSKILL.md
Developing New Attachables
When to use this skill
Use this skill when turning an Eloquent model into a content attachment for rich text editors (e.g., user mentions, embedded resources), or when creating custom non-model attachables (e.g., OpenGraph embeds).
Making a Model Attachable
1. Implement the Contract and Use the Trait
The model must implement AttachableContract and use the Attachable trait:
@verbatim
@endverbatim
2. Implement the richTextRender() Method
This is the only required method. It returns the HTML used when displaying the attachment outside the editor:
@verbatim
@endverbatim
The $options array may contain an in_gallery boolean when the attachment is rendered inside a gallery.
3. Create the Blade Partial
Create a Blade view that renders the attachment's HTML. This is the content end users will see:
@verbatim
@endverbatim
4. Optional: Plain Text and Markdown Representations
For plain text export (toPlainText()), implement:
@verbatim
@endverbatim
For Markdown export (toMarkdown()), implement:
@verbatim
@endverbatim
If these methods are not implemented and no caption is stored, the attachment won't appear in the respective output.
5. Optional: Override Default Trait Methods
The Attachable trait provides sensible defaults for these methods, but you can override them:
richTextContentType(): string— defaults to'application/octet-stream'richTextFilename(): ?string— defaults tonullrichTextFilesize(): ?int— defaults tonullrichTextPreviewable(): bool— defaults tofalserichTextMetadata(?string $key = null): mixed— defaults tonull
6. Using a Separate Trait for Organization
For better organization, extract the attachable behavior into its own trait:
@verbatim
@endverbatim
Then use it on the model:
@verbatim
@endverbatim
Custom Attachables Without SGIDs
For attachments that don't need a database record (e.g., OpenGraph embeds), implement AttachableContract directly on a plain class and register a custom resolver:
@verbatim
@endverbatim
The class must implement toRichTextAttributes(), equalsToAttachable(), and richTextRender(). Use a content-type attribute on the node to identify your custom attachment type:
@verbatim
@endverbatim
How SGIDs Work
The Attachable trait automatically generates a Signed Global ID (SGID) for the model via richTextSgid(). This SGID is stored in the <rich-text-attachment sgid="..."> tag in the canonical HTML. When content is rendered, the AttachableFactory resolves the SGID back to the original model. SGIDs are signed using your APP_KEY and never expire for rich text attachments.
Frontend: Creating Attachments in the Editor
On the frontend, create attachments in the editor when a user selects an attachable. The key data needed from your API endpoint is:
sgid— the model's Signed Global IDcontent— the HTML to display inside the editor
For Trix, create a new Trix.Attachment({ sgid, content, contentType: '...' }) and insert it. For Lexxy or custom editors, the mechanism differs but the concept is the same: embed an attachment node with the sgid attribute.
Retrieving Attachables from Content
After saving, extract all attachables of a specific type:
@verbatim
@endverbatim
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingresources/boost/skills/developing-new-attachables/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/tonysm/rich-text-laravel/developing-new-attachables)