Custom Collections and Singletons in Cockpit CMS
We received a request: "We need an admin panel where a manager adds products, and cards with photos, categories, and attributes appear on the site. Without an admin panel, we'd have to write a REST API from scratch." Cockpit CMS solves this in an hour: create a "Products" collection with fields (title, price, image), link categories via collectionlink, and use a repeater for attributes. A ready JSON endpoint appears immediately — the frontend fetches data via a GET request. We've used Cockpit CMS in 50+ headless projects — this headless system gives flexibility through Collections and Singletons. In 4–8 hours we set up the structure, fields, relations, and access rights, while editors get an intuitive interface without extra code. Our experience: 5 years on the market, over 50 projects on Cockpit. Compared to building a custom admin panel from scratch, you save up to 60% time and up to 50% budget. Starting from $500 for a basic setup.
What problems do we solve with collections?
The typical pain point is manually creating an API for content management. Cockpit automatically generates REST endpoints for each collection. The second problem is the complexity of relationships between entities. In Cockpit, relations are configured via the collectionlink field type without SQL queries. The third is the need for access control. Cockpit supports roles: administrator, editor, content manager. In 80% of projects we use relations between 3–5 collections.
How to create a collection via API?
Collections can be created through the Admin UI or programmatically via the REST API. Here's an example for a "Products" collection:
$collection = [ 'name' => 'products', 'label' => 'Products', 'fields' => [ ['name' => 'title', 'type' => 'text', 'required' => true, 'label' => 'Title'], ['name' => 'slug', 'type' => 'text', 'required' => true, 'slug' => true], ['name' => 'description', 'type' => 'wysiwyg', 'label' => 'Description'], ['name' => 'price', 'type' => 'number', 'label' => 'Price'], ['name' => 'image', 'type' => 'asset', 'label' => 'Photo'], ['name' => 'gallery', 'type' => 'gallery', 'label' => 'Gallery'], ['name' => 'category', 'type' => 'collectionlink', 'link' => 'categories'], ['name' => 'published', 'type' => 'boolean', 'default' => false], ['name' => 'publishedAt', 'type' => 'date'], ], 'sortable' => true, 'in_menu' => true, ]; After that, a POST request creates the collection in Cockpit. Records are immediately accessible via API or admin panel. The whole process takes 5–10 minutes. As stated in the official Cockpit CMS documentation: Cockpit GitHub Repository, the API is fully RESTful.
Field types in Cockpit
Cockpit supports 20+ field types. Here are the main ones:
| Type | Description | Example use |
|---|---|---|
text |
String up to 255 chars | Product name |
textarea |
Multi-line text | Article description |
wysiwyg |
Rich text editor (TinyMCE) | Post content |
markdown |
Markdown | Technical documentation |
number |
Number (int/float) | Price, weight |
boolean |
Toggle yes/no | Published |
select |
Dropdown list | Product category |
asset |
Single file/image | Main photo |
gallery |
Image gallery | Product photos |
date / time |
Date/time | Publication date |
color |
Color picker | Background color |
collectionlink |
Link to another collection's record | Related post |
repeater |
Repeatable field groups | Feature blocks |
layout |
Page builder | Homepage |
object |
JSON object | Integration settings |
tags |
Tags (array of strings) | Search tags |
set |
Reusable field group | Contact details |
You can combine fields in any order. For relations between collections we use collectionlink — it automatically pulls records from the linked collection.
How to set up relations between collections?
Relations between collections are configured via the collectionlink field type. Specify the target collection and whether multiple records can be selected. Cockpit automatically creates a searchable dropdown. For example, a product can select a category from the categories collection. This is analogous to a foreign key in relational databases but without SQL.
Collection vs Singleton: when to use which?
| Criteria | Collection | Singleton |
|---|---|---|
| Number of records | Many (hundreds/thousands) | One |
| Example | Articles, products, users | Site settings, SEO, contacts |
| API endpoint | /api/collections/items/{id} | /api/singletons/{name} |
| Access rights | Per record | At singleton level |
Singletons are convenient for settings: SEO tags, contacts, social media, banners. Example structure for a "Homepage" singleton:
{ "fields": [ { "name": "hero_title", "type": "text" }, { "name": "hero_subtitle", "type": "textarea" }, { "name": "hero_image", "type": "asset" }, { "name": "featured_posts", "type": "collectionlink", "link": "posts", "multiple": true }, { "name": "seo_title", "type": "text" }, { "name": "seo_description", "type": "textarea" } ] } The editor fills in the fields, and the frontend gets a ready JSON via API. No extra logic required.
Using Repeater for content blocks
Repeater allows adding any number of repeatable blocks. For example, a "Features" block:
{ "name": "features", "type": "repeater", "label": "Features", "fields": [ { "name": "icon", "type": "asset" }, { "name": "title", "type": "text" }, { "name": "description", "type": "textarea" } ] } In the admin panel, the editor sees an "Add block" button — each new block pulls the same fields. This is more convenient than storing HTML in a text field. We use repeater in 90% of projects.
What's included in the work
- Data structure analysis — define collections, relations, and fields for your business entities (2–4 hours).
- Schema creation — configure collections, singletons, and their fields via Admin UI or API (4–8 hours).
- Access rights setup — role differentiation (administrator, editor, content manager) (1–2 hours).
- API documentation — describe endpoints for frontend or integrations (2–4 hours).
- Team training — show how to use the admin panel, add records and blocks (2–4 hours).
- Post-launch support — fix bugs, tweak fields as needed (up to 7 days).
How we work
- Analysis — study the content structure, gather requirements.
- Design — create an ER diagram of collections and relations.
- Implementation — configure Cockpit, write custom fields/validators if needed.
- Testing — check scenarios: create, edit, delete records, access rights.
- Deployment — deploy on the server, configure backups.
Timelines: from 1 day to 2 weeks, depending on complexity. Cost is calculated individually. Get a consultation — our engineers will help estimate the project and timelines. Order Cockpit CMS setup turnkey, get a ready admin panel without extra code. We guarantee results on time. Write to us to estimate your project.







