Download the PHP package plank/contentable without Composer
On this page you can find all versions of the php package plank/contentable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download plank/contentable
More information about plank/contentable
Files in plank/contentable
Package contentable
Short Description Create dynamic pages using polymorphic relationships and special Module classes
License MIT
Homepage https://github.com/plank/contentable
Informations about the package contentable
Laravel Contentable
⚠️ This package is currently in development and is not ready for production use. ⚠️
This package allows for models to be built up dynamically by attaching Content
to it. It's intended use is to allow for
creating a module system that plays nicely with Laravel Nova (via Repeaters, or other block editing systems) to create user
defined pages.
Considerations have been made to keep this package compatible with other packages in the Plank ecosystem such as Snapshots. It also has been architected to allow for explicit linking between modules and other entities within an application.
Table of Contents
- Installation
- Quick Start
- Configuration
- Usage
- Contributing
- Credits
- License
- Security Vulnerabilities
Installation
You can install the package via composer:
Quick Start
Once the installation has completed, to begin using the package:
- Add the
HasContent
trait andContentable
interface to any model you'd like to attach content too. - Add the
CanRender
trait andRenderable
interface to any models that will act as "Modules". - Implement the missing
Renderable
interface methods, specifically therenderHtml()
method. Optionally add a$renderableFields
class property, listing all fields that should be accessed by the module.
Configuration
The package's configuration file is located at config/contentable.php
. If you did not publish the config file during installation, you can publish the configuration file using the following command:
Usage
Building a Module system
Contentable's main purpose is to ease the building of a page builder style experience while maintaining explicit relationships
between Renderable
models and any other arbitrary models within the application. This enables easily building things like
"Callout" modules, that can link to a concrete record in the database.
Define Modules
To take advantage of the above approach, any modules that are distinct from each other must be defined as their own models. Eg, you might define a simple "Text" module (that is, a section on a page that displays a title and body text) like so:
Of course, associated migrations, factories, etc... would need to be generated as well.
Define Contentables
Once modules have been created, though, they can then be attached to some Contentable
, such as a Page
model
eg:
Such a page can now have any number of modules attached to it, and rendered. This allows most Laravel oriented content management
systems to simply relate a module to a Page
via a (polymorphic) relationship field.
You can even get creative and use repeater style fields to build up a page's content in a more editorial fashion!
Layouts
Layouts enable the user to control the "window dressing" around the modules that are laid out on a page. Effectively, a
layout represents the template used by a Contentable
model (or any other model for that matter).
Layouts natively support Blade templates and Inertia pages.
Layouts are created automatically when Blade / JS files are created in the appropriate locations.
By default, these locations are resources/views/layouts
for Blade templates or resources/js/Pages/Layouts
for Inertia based systems.
Calling the function php artisan contentable:sync
will scan these directories
Layoutables
Typically, any model with that fulfils the Conentable
contract will also want to be Layoutable
. This allows
users to have full control over the display modes on a page. The above Page
model can be extended as so to add Layout functionality:
Contentable exposes a function that make it easy to have a particular instance of a model use its set layout. Simply call ->layout()
on it, and pass that to the chosen render function.
eg:
Contributing
Please see CONTRIBUTING for details.
Credits
- Kurt Friars
- Massimo Triassi
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
Security Vulnerabilities
If you discover a security vulnerability within siren, please send an e-mail to [email protected]. All security vulnerabilities will be promptly addressed.
All versions of contentable with dependencies
spatie/laravel-package-tools Version ^1.14.0
illuminate/contracts Version ^10.0|^11.0