Collections and Custom Post Types
Posts are a generic content type. They can be used for blog posts, news articles, or any other type of content that is made up of a title, body, and other fields. Unlike content attached directly to pages (such as a hero image), posts are typically shown in lists (such as the latest news) and accessed dynamically.
Collections provide a blueprint for creating and managing posts. For example, you may wish to create a collection of movies. The collection has a schema that defines which fields are used for each movie such as Title, Director, Year of Release, and so on. Every post stores its collection's slug in posts.post_type.
Creating a collection
Collections are created in the admin, under Collections → Create. Saving a new collection creates its folder, resources/views/wrangler/posts/{slug}/, with two files:
| File | Holds |
|---|---|
schema.json |
The extra fields each post has, edited in the admin's schema editor. See Collection Schema. |
config.json |
How the admin manages the collection: widgets, index views and table columns. See Collection Configuration. |
The slug names a folder on disk, so it may only use letters, numbers, hyphens and underscores. Commit these files with the site, like other views.
Settings you change in the admin are saved on the collection's database row (collections.config) and override the matching top-level keys of config.json. The schema is always read from schema.json.
A collection's Searchable setting decides whether its posts are indexed by Laravel Scout. See Search.
Showing a collection on pages
Posts reach pages through page blocks. textstem:make:collection generates a block class for that; despite its name, it doesn't create the collection itself:
php artisan textstem:make:collection Venue
This creates app/Wrangler/Components/Venue.php, a page block you then fill in to list or show venues. With --wc it also creates resources/views/wrangler/components/venue/default.blade.php.
Known issue: with
--wc, the command copies the raw stub over the class it has just generated, leavingclass DummyClassinVenue.php. Rename the class toVenueby hand.
See Creating Page Components for writing the block. A collection control lets editors pick posts, for example 'source' => 'posts:venue' (see Editor Setup).
Content Packs
Content packs are zip files containing
- custom schema
- configuration
- any custom components for displaying the custom posts
Editors install them from the admin; see Installing Content Packs.
See also: Creating Collections, in the User Guide.