diff --git a/README.md b/README.md index 64cf69c..bf60f1c 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,13 @@ ⚠️ 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](https://github.com/plank/snapshots). +It also has been architected to allow for explicit linking between modules and other entities within an application. + ## Table of Contents - [Installation](#installation) @@ -32,16 +39,13 @@ You can install the package via composer: composer require plank/contentable ``` -You can use the package's install command to complete the installation: - -```bash -php artisan contentable:install -``` - ## Quick Start Once the installation has completed, to begin using the package: +1. Add the `HasContent` trait and `Contentable` interface to any model you'd like to attach content too. +2. Add the `CanRender` trait and `Renderable` interface to any models that will act as "Modules". +3. Implement the missing `Renderable` interface methods, specifically the `renderHtml()` method. Optionally add a `$renderableFields` class property, listing all fields that should be accessed by the module. ## Configuration @@ -49,17 +53,139 @@ The package's configuration file is located at `config/contentable.php`. If you ```bash php artisan vendor:publish --tag=contentable-config +# Be sure to run any associated migrations +php artisan migrate ``` ## 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: + +```php +{$this->title}" + + "
{$this->body}
"; + } +} +``` + +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: +```php +layout()` on it, and pass that to the chosen render function. + +eg: +```php +public function show(Page $page): \Illuminate\View\View +{ + return view($page->layout())->with(compact('page')); +} +```