PHP Laravel Backend for Headless CMS
How do you construct with Laravel the backend of a headless CMS?
What is Headless CMS
A headless CMS (Content Management System) has a web interface only for creating content but no web interface for showing content to the audience.
The advantage of a headless CMS is that you do not impose a particular way of content display. So you are free to construct your SPA (Single Page Application) to display content.
After years of using different CMS, we expect that creating and displaying content through a CMS, whether headless or not, has to support certain activities.
Pieces of content, such as articles, are written and rewritten over hours or days. An author seldom publishes a piece of content in the same session in which he/she started to compose it.
Consequently, the backend of a CMS has to store and update drafts before publishing content.
An enterprise-grade CMS requires a flow of approval for each piece of content. So an article is written, reviewed, and then approved.
The backend of a CMS has to implement such an approval workflow.
Once the content is displayed, we expect readers to comment on each piece of content and to comment on comments.
So the backend of a CMS has to store threads of comments.
It is natural to tag content, so it would be easier for readers to grasp the topics the content talks about instantly.
So the backend has to store tags on pieces of content.
Reviews and Ratings
Content readers would add reviews and assign ratings to the different kinds of content. Be it articles or videos.
Such reviews should be moderated and approved to fit standard public guidelines on content.
Laravel Packages to Do the Job
One should consider that pieces of content can come from different types of models in the same CMS, such as articles, posts, and pages.
We would use the following packages:
- Laravel Drafts - do manage drafts and revisions
- Laravel Comments - store comments on models
- Approval - approve a model before it is persisted
- Laravel Tags - tag a model
- Laravel Reviews - add reviews and ratings to a model. Reviews are moderated and undergo approval.
The Next Step
To have a genuinely extensible headless CMS, the user should be able to deploy an extensible set of models.
We will create a Laravel command to deploy new models into the CMS. Such a command will generate:
And possibly more, as a headless CMS should have extensible headless navigation.