From 637d93615ffb61ffc16bd68a738fa3cd46169bc0 Mon Sep 17 00:00:00 2001 From: Massimo Triassi Date: Mon, 17 Jun 2024 16:30:09 -0400 Subject: [PATCH 1/3] docs: #12 add basic install/overview/quick start section --- README.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 64cf69c..0fe699b 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 @@ -55,6 +59,7 @@ php artisan vendor:publish --tag=contentable-config ## Usage + ### Layouts ### Layoutables From 6ae8fa1e0df0aee881323557e7d5f87cda8f48f5 Mon Sep 17 00:00:00 2001 From: Massimo Triassi Date: Tue, 18 Jun 2024 16:52:37 -0400 Subject: [PATCH 2/3] docs: #12 add more robust Usage section --- README.md | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0fe699b..1473e8e 100644 --- a/README.md +++ b/README.md @@ -53,18 +53,130 @@ 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 + Date: Tue, 18 Jun 2024 17:01:28 -0400 Subject: [PATCH 3/3] docs: #12 add missing ->layout() usage --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 1473e8e..bf60f1c 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,15 @@ class Page extends Model implements Contentable, Layoutable protected static $globalLayouts = false; } ``` +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: +```php +public function show(Page $page): \Illuminate\View\View +{ + return view($page->layout())->with(compact('page')); +} +```