From 40433a9bb9807ed5ebc6af9e174cba9e1088df2d Mon Sep 17 00:00:00 2001 From: Shea Date: Thu, 17 Oct 2024 15:09:26 +1300 Subject: [PATCH] complete docs sections, update branding --- docs/.vitepress/config.mts | 19 +- docs/.vitepress/theme/custom.css | 94 ++++++++-- docs/assets/ic_logo_landscape.svg | 19 ++ docs/assets/ic_logo_landscape_dark.svg | 72 ++++++++ docs/assets/slice1bdark.svg | 12 -- docs/assets/slice1blight.svg | 12 -- docs/filament-php.md | 2 +- docs/index.md | 9 +- docs/introduction.md | 210 +++------------------- docs/managing-context.md | 20 +-- docs/model-events.md | 6 +- docs/preparing-your-models.md | 21 +-- docs/publishing.md | 34 ++-- docs/versioning.md | 7 +- src/Filament/PublishStatusTableColumn.php | 33 ---- src/Revisor.php | 10 +- tests/MigrationsTest.php | 4 +- tests/TestCase.php | 4 +- 18 files changed, 261 insertions(+), 327 deletions(-) create mode 100644 docs/assets/ic_logo_landscape.svg create mode 100644 docs/assets/ic_logo_landscape_dark.svg delete mode 100644 docs/assets/slice1bdark.svg delete mode 100644 docs/assets/slice1blight.svg delete mode 100644 src/Filament/PublishStatusTableColumn.php diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index f2433bf..6549649 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -6,18 +6,12 @@ export default defineConfig({ description: "Revisor is a robust versioning and publishing system for Laravel Eloquent Models.", cleanUrls: true, themeConfig: { - logo: { - light: '/assets/slice1blight.svg', - dark: '/assets/slice1bdark.svg', - }, - siteTitle: false, + // logo: { + // light: '/assets/ic_logo_landscape.svg', + // dark: '/assets/ic_logo_landscape_dark.svg', + // }, + siteTitle: 'Laravel Revisor', // https://vitepress.dev/reference/default-theme-config - nav: [ - {text: "IndraCollective", link: "https://indracollective.dev"}, - // {text: "Home", link: "/"}, - // {text: "Docs", link: "/introduction"}, - // { text: "Support Us", link: "https://indracollective.dev/support" }, - ], sidebar: [ { @@ -46,13 +40,14 @@ export default defineConfig({ {text: "FilamentPHP", link: "/filament-php"}, ], }, + {text: "IndraCollective", link: "https://indracollective.dev"}, ], }, ], socialLinks: [ {icon: "github", link: "https://github.com/indracollective/laravel-revisor"}, - {icon: "twitter", link: "https://twitter.com/livesourcenz"}, + {icon: "twitter", link: "https://x.com/indracollective"}, ], footer: { message: "Released under the MIT License.", diff --git a/docs/.vitepress/theme/custom.css b/docs/.vitepress/theme/custom.css index bc63199..e5cdeed 100644 --- a/docs/.vitepress/theme/custom.css +++ b/docs/.vitepress/theme/custom.css @@ -1,26 +1,86 @@ :root { - --vp-c-brand-1: #a45af8; - --vp-c-brand-2: #b778ff; - --vp-c-brand-3: #a45af8; - --vp-c-bg-soft: #f0f2fc; - --vp-button-alt-bg: #f0f2fc; - --vp-button-alt-hover-bg: #f2f5f8; + --vp-c-brand-1: #22c55e; + --vp-c-brand-2: #4ade80; + --vp-c-brand-3: #16a34a; + --vp-c-text-1: #1e293b; + --vp-c-text-2: #475569; + --vp-c-text-3: #64748b; + + --vp-c-bg: #ffffff; + --vp-c-bg-soft: #f1f5f9; + --vp-c-bg-alt: #e2e8f0; + + --vp-button-brand-bg: var(--vp-c-brand-1); + --vp-button-brand-hover-bg: var(--vp-c-brand-3); + --vp-button-brand-active-bg: var(--vp-c-brand-3); + + --vp-button-alt-bg: var(--vp-c-bg-soft); + --vp-button-alt-hover-bg: var(--vp-c-bg-alt); + + --vp-sidebar-bg-color: var(--vp-c-bg-soft); + } .dark { - --vp-c-bg: #020617; - --vp-c-bg-soft: #0a0e1f; - --vp-c-bg-alt: #01020e; - --vp-button-alt-bg: #0a0e1f; - --vp-button-alt-hover-bg: #1b2240; + --vp-c-text-1: #f1f5f9; + --vp-c-text-2: #94a3b8; + --vp-c-text-3: #64748b; + + --vp-c-bg: #0F1829; + --vp-c-bg-soft: #1e293b; + --vp-c-bg-alt: #1b2333; + + --vp-sidebar-bg-color: var(--vp-c-bg-soft); + + --vp-c-border: #334155; + --vp-c-divider: #334155; + --vp-c-gutter: #1e293b; + +} + +.tagline { + color: var(--vp-c-text-1) !important; +} + +.VPNavBar.home .title { + width: 150px; + color: transparent !important; + background-image: url('/assets/ic_logo_landscape.svg'); + background-size: contain; + background-repeat: no-repeat; + background-position: center; +} + +.dark .VPNavBar.home .title { + background-image: url('/assets/ic_logo_landscape_dark.svg'); +} + +.VPSidebarItem.level-1.is-link { + position: fixed; + bottom: 0; + left: 0; + right: 0; + background-color: var(--vp-c-bg-soft); + padding: 16px 0; + border-top: 1px solid var(--vp-c-divider); +} + +.VPSidebarItem.level-1.is-link a { + width: 100%; + height: 100%; + background-image: url('/assets/ic_logo_landscape.svg'); + background-repeat: no-repeat; + background-position: center; +} + +.dark .VPSidebarItem.level-1.is-link a { + background-image: url('/assets/ic_logo_landscape_dark.svg'); } -.VPHomeHero .text { - font-size: 32px; +.VPSidebarItem.level-1.is-link a:after { + display: none; } -@media (min-width: 640px) { - .VPHomeHero .text { - font-size: 50px; - } +.VPSidebarItem.level-1.is-link p { + margin-left: -10000px; } diff --git a/docs/assets/ic_logo_landscape.svg b/docs/assets/ic_logo_landscape.svg new file mode 100644 index 0000000..1352e3e --- /dev/null +++ b/docs/assets/ic_logo_landscape.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/docs/assets/ic_logo_landscape_dark.svg b/docs/assets/ic_logo_landscape_dark.svg new file mode 100644 index 0000000..440c4f3 --- /dev/null +++ b/docs/assets/ic_logo_landscape_dark.svg @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/assets/slice1bdark.svg b/docs/assets/slice1bdark.svg deleted file mode 100644 index 221a18c..0000000 --- a/docs/assets/slice1bdark.svg +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/docs/assets/slice1blight.svg b/docs/assets/slice1blight.svg deleted file mode 100644 index 88611f0..0000000 --- a/docs/assets/slice1blight.svg +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/docs/filament-php.md b/docs/filament-php.md index d4cc122..09e2d38 100644 --- a/docs/filament-php.md +++ b/docs/filament-php.md @@ -1,4 +1,4 @@ # FilamentPHP -## Published Status Table Column +A Revisor FilamentPHP plugin is currently under development. Follow us on [X/Twitter](https://twitter.com/indracollective) for updates. diff --git a/docs/index.md b/docs/index.md index 7bbbbeb..986c13c 100644 --- a/docs/index.md +++ b/docs/index.md @@ -4,7 +4,6 @@ layout: home hero: name: "Laravel Revisor" - text: "By IndraCollective" tagline: "Robust Draft, Publishing and Versioning\nfor Laravel Eloquent Models." actions: - theme: brand @@ -16,9 +15,9 @@ hero: features: - title: Seamless Database Design - details: Separate, complete database tables for Draft, Published and Version history records per Eloquent Model, reducing exposure to the added complexity of context-dependent records - - title: Intuitive API - details: Super simple, feature complete API for Publishing and Versioning records, including Version rollbacks, pruning and more. + details: Separate, complete database tables for Draft, Published and Version history records per Eloquent Model. + - title: Beautiful API + details: Everything you need to manage Publishing and Versioning records including Version rollbacks, pruning and more in a simple and intuitive API. - title: Flexible Context Management - details: Easily switch between Draft, Published and Version contexts at any level including Global Config, Route Middleware, Query Scopes and context-isolating Closures. + details: Easily move between Draft, Published and Version contexts at any level; Global Config, Route Middleware, Query Scopes and more. --- diff --git a/docs/introduction.md b/docs/introduction.md index 74691d5..1ca7583 100644 --- a/docs/introduction.md +++ b/docs/introduction.md @@ -1,206 +1,54 @@ # Introduction -Laravel Revisor is a robust draft, versioning and publishing system for Laravel Eloquent Models. +Laravel Revisor provides robust draft, publishing and versioning for Laravel Eloquent Models. -✅ Separate, complete database tables for draft, published and version history records of each Model +There are a good handful of Laravel versioning packages out there with varying approaches. Revisor aims to overcome their different trade-offs, offering maximum power, flexibility and interoperability with minimum exposure to complexity. -✅ Migration API for easily creating/modifying draft, published and version history tables +## Design Goals -✅ Easy context management for setting the appropriate reading/writing "mode" at all levels of operation, from global -config, to middleware, mode callbacks and query builder. +### 1. Draft, Published and Versioned record data should be clearly distinguished and cleanly instantiable as Eloquent Models. -✅ Clean, flexible API for drafting, publishing and version management +Revisor provides everything you need to seamlessly manage your Draft, Published and Version records in separate, complete tables for each Model. For example - a `Page` model would have 3 tables; `pages_published`, `pages_drafts` and `pages_versions`. -✅ High configurability and excellent documentation - -### Concepts - -#### Modes - -... - -#### Tables - -... - -#### Base table - -### Installation - -Install the package via composer: - -```bash -composer require indra/laravel-revisor -``` - -### Configuration - -Publish the package configuration to your application: - -```bash -php artisan vendor:publish --tag="laravel-revisor-config" -``` - -The following configurations will then be available in you app in config/revisor.php - -```php -return [ - // The default mode determines which table will be read/written to by default - // The RevisorContext enum is used to define the possible values for this - // which are `Draft`, `Version` and `Published` - 'default_context' => RevisorContext::Published, - - // The table suffixes are used to define the table names for each mode - // The keys are the values of the RevisorContext enum - // The values are the table suffixes - 'table_suffixes' => [ - RevisorContext::Draft->value => '_drafts', - RevisorContext::Version->value => '_versions', - RevisorContext::Published->value => '_published', - ], - - // The publishing config is used to determine the default publishing behaviour, - 'publishing' => [ - // If true, records will be automatically published on created - 'publish_on_created' => false, - // If true, records will be automatically published on updated - 'publish_on_updated' => false, - ], - - // The publishing config is used to determine the default versioning behaviour, - 'versioning' => [ - // If true, new version records will be automatically created when drafts are created - 'save_new_version_on_created' => true, - // If true, new version records will be automatically created when drafts are updated - 'save_new_version_on_updated' => true, - // The maximum number of versions to keep - // if set to true, version records will not be pruned - 'keep_versions' => 10, - ], -]; -``` - -## Usage - -### 1. Write your Migrations - -Revisor operates on 3 tables (draft, published, versions) per model and provides convenient methods for applying and -synchronising migrations across these tables. - -#### Creating New Tables - -Below is an example migration that creates database tables for a revisor-enabled `Page` model +This allows for a clear separation of concerns and reduces exposure to the complexity inherent in managing multiple versions of records. ```php -use Illuminate\Database\Migrations\Migration; -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Support\Facades\Schema; -use Indra\Revisor\Facades\Revisor; - -return new class extends Migration +// Example: A Revisor migration creates/alters 3 tables for each Model +public function up(): void { - public function up(): void - { - Revisor::createTableSchemas('pages', function (Blueprint $table) { - $table->id(); - $table->string('title'); - }); - } + Revisor::createTableSchemas('pages', function (Blueprint $table) { + $table->id(); + $table->string('title'); + }); } ``` -The `Revisor::createTableSchemas` will use the `baseTableName` given as the first argument to create all 3 -`page_drafts`, `page_versions` and `page_published` tables. As with regular Laravel migrations, the callback passed in -the second argument will be used to build the table schemas according to your needs. +### 2. Context Management should be intuitive and powerful enough to handle any scenario -Revisor will also add the following extra columns to your tables for as follows: +Context Management refers the ability to switch between Draft, Published and Version states of your data. -| Column | Type | Purpose | -|----------------|-----------------|----------------------------------------------------| -| publisher | nullableMorphs | User who published the record | -| published_at | timestamp | When the record was published | -| is_published | boolean | Whether the record is published | -| is_current | boolean | Whether the record is the current version | -| version_number | unsignedInteger | Sequential version number | -| record_id | foreignKey | id of draft/published record (versions table only) | +Revisor allows you to switch contexts at any level you will need: from Global Config, Middleware, context-isolating Closures and Query Builder. Precedence is given to the most specific context. -#### Amending Existing Tables - -Amending/modifying table schemas can be done in much the same way as creating new ones, by using the `amendTableSchemas` -method on the Revisor Facade: +Under the hood, the active `RevisorContext` determines which table will be read/written when interacting with your Eloquent Models. ```php -use Illuminate\Database\Migrations\Migration; -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Support\Facades\Schema; -use Indra\Revisor\Facades\Revisor; - -return new class extends Migration -{ - public function up(): void - { - Revisor::amendTableSchemas('pages', function (Blueprint $table) { - $table->string('heading')->change(); - $table->text('content')->nullable(); - }); - } -} -``` - -Run you migrations as usual with: - -```bash -php artisan migrate +Revisor::withDraftContext(function() { + // all draft pages + $pages = Page::all(); + + // all published pages + $publishedPages = Page::withPubslishedContext()->all(); +}); ``` -Review the generated database schema in your favourite UI to familiarise yourself. - -### 2. Set up your Models - -Revisor enabled Models require the `HasRevisor` trait and the `HasRevisor` interface. - -Additionally, a protected `$baseTable` property can be defined in place of the optional `$table` property sometimes -defined on Eloquent Models. This allows the Model's `$table` property to be defined dynamically by this package, -depending on which of the draft/published/versions tables you want to read/write. - -```php -namespace App\Models; - -use Illuminate\Database\Eloquent\Model; -use Indra\Revisor\Concerns\HasRevisor; -use Indra\Revisor\Contracts\HasRevisor as HasRevisorContract; - -class Page extends Model implements HasRevisorContract -{ - use HasRevisor; - - protected string $baseTable = 'pages'; - - ... -``` - -### Modes - -#### About Modes - -#### Global Config - -#### Middleware - -### Interacting with Revisor Records +### 3. Simple and easy to follow -#### Creating a draft +Revisor ensures versioning and publishing procedures are uni-directional. Use of Global Scopes and Model Events are kept to a minimum. -#### Publishing +The active `RevisorContext` is registered with [Laravel's Context Store](https://laravel.com/docs/context), ensuring it is visible in logs and error pages. -##### Publishing +--- -##### Unpublishing +  - - Hooks - - Versioning - - Creating versions - - Updating versions - - Reverting to versions - - Pruning versions - - Hooks__ +If all that aligns with your requirements, great! Let's dive in and publish/version all the things! diff --git a/docs/managing-context.md b/docs/managing-context.md index c0312ae..52d6c78 100644 --- a/docs/managing-context.md +++ b/docs/managing-context.md @@ -12,20 +12,18 @@ your Models querying the following tables: | `RevisorContext::Version` | `pages_versions` | ::: info NOTE -All examples below are in the context of `RevisorContext::Draft`, and a Revisor-enabled `Page` Model +All examples below are in the context of `RevisorContext::Draft` and a Revisor-enabled `Page` Model. ::: ## Setting the Active Context -There are multiple levels at which you may want to set the active `RevisorContext`. They are listed below in order of +There are a few levels at which you may want to set the active `RevisorContext`. They are listed below in order of precedence. ### 1. Global Default, via Config -::: info NOTE By default, Revisor will use the `RevisorContext::Published` mode. This is recommended for most use cases, to avoid unintentionally exposing draft records. -::: ```php // config/revisor.php @@ -60,7 +58,7 @@ $page = Page::first(); ### 3. Local Override via Closures -To override both the above Global `RevisorContexts` inside a Closure, use the `withPublishedContext`, `withDraftContext` +To override both the Global `RevisorContexts` within an isolated scope, use the `withPublishedContext`, `withDraftContext` or `withVersionContext` method on the `Revisor` facade. @@ -78,10 +76,12 @@ Under the hood, this temporarily sets the `RevisorContext` in Laravel's Context `RevisorContext` after the closure has been executed. ::: -### 4. Local Override on the Model / Query Builder via Scopes +### 4. Local Override on the Model / Query Builder via Query Scopes + +Setting the `RevisorContext` on an Eloquent Model or Builder will override all other activated `RevisorContext` for that Model or +Builder instance only. -Setting the `RevisorContext` on a Model or Query will override all other activated `RevisorContext`, for that Model or -Builder instance. This can be achieved by using the Local Query Scope methods `withDraftContext`, +This can be achieved by using the Local Query Scope methods `withDraftContext`, `withPublishedContext` or `withVersionContext` on your Model or Query Builder. ```php @@ -97,7 +97,7 @@ Revisor provides 3 Middleware Classes to help you set the `RevisorContext` on sp ### DraftMiddleware -Useful for routes that should primarily be used for editing Draft records +Useful for routes that should primarily be used for editing Draft records, such as an admin panel. ```php use Illuminate\Support\Facades\Route; @@ -111,7 +111,7 @@ Route::group('/admin', function () { ### DraftableMiddleware Similar to `DraftMiddleware` but only activates `RevisorContext::Draft` if the Request contains a `?draft` query -parameter. This is useful for optionally enabling Draft mode on a Route/Group ie. when allowing users to preview a draft +parameter. This is useful for optionally enabling Draft mode on a Route/Group, ie. when allowing users to preview a draft record. ### PublishedMiddleware diff --git a/docs/model-events.md b/docs/model-events.md index fcccded..12a8dc4 100644 --- a/docs/model-events.md +++ b/docs/model-events.md @@ -1,11 +1,11 @@ # Model Events -Laravel Revisor provides several model events for you hook into key publishing and versioning events. +Laravel Revisor fires several Model Events for you hook into key publishing and versioning events. -All events are fired on the Draft record, and pass the relevant published or versioned record as an argument to your +All events are fired on the Draft record, and pass the relevant Published or Versioned record as an argument to your callback (if applicable). -Event listeners can be registered using static methods on the Model class that correspond to the event name. +Event listeners can be registered using static methods on the Model class. The method names correspond to the event name. ```php Page::published(function (Page $page, Page $publishedRecord) { diff --git a/docs/preparing-your-models.md b/docs/preparing-your-models.md index 16aaaac..92b6a81 100644 --- a/docs/preparing-your-models.md +++ b/docs/preparing-your-models.md @@ -62,10 +62,10 @@ Revisor's `createTableSchemas` method will add the following extra columns to yo | version\_number | unsignedInteger | Sequential version number | | record\_id | foreignKey | id of draft/published record (versions table only) | -### Amending Existing Revisor Tables +### Altering Existing Revisor Tables -Modifying existing Revisor table schemas can be done in much the same way as creating new ones. This time we'll -the `amendTableSchemas` method on the `Revisor` Facade: +Modifying existing Revisor table schemas can be done in much the same way as creating new ones. This time we'll call +the `alterTableSchemas` method on the `Revisor` Facade: ```php use Illuminate\Database\Migrations\Migration; @@ -77,7 +77,7 @@ return new class extends Migration { public function up(): void { - Revisor::amendTableSchemas('pages', function (Blueprint $table) { + Revisor::alterTableSchemas('pages', function (Blueprint $table) { $table->string('heading')->change(); $table->text('content')->nullable(); }); @@ -91,8 +91,6 @@ Run you migrations as usual with: php artisan migrate ``` -Review the generated database schema in your favourite DB tool to familiarise yourself with the Revisor database schema. - ### Retrofitting Existing Models/Tables If you are needing to add Revisor to Models in your application that already have production data stored, we recommend @@ -104,11 +102,6 @@ importing the data from the old single table into the new `Draft` and `Published Adding Revisor to your Models is as simple as implementing the `HasRevisor` Interface and Trait. -::: tip Note -You can define a `$baseTable` property in place of the usual `$table` property, for -cases where your desired table name is not what Laravel would otherwise assume based on your Model class name. -::: - This should leave your Model looking something like this: ```php @@ -123,5 +116,9 @@ class Page extends Model implements HasRevisorContract protected string $baseTable = 'pages'; ... - ``` + +::: tip Note +You can define a `$baseTable` property in place of the usual `$table` property, for +cases where your desired table name is not what Laravel would otherwise assume based on your Model class name. +::: diff --git a/docs/publishing.md b/docs/publishing.md index d85fa27..56ab237 100644 --- a/docs/publishing.md +++ b/docs/publishing.md @@ -1,7 +1,7 @@ # Publishing -When a record is Published, the publishing related columns (is_published, published_at etc) are updated on the Draft -record, and the Draft record is inserted into the Published table. +When a record is Published, the [publishing related columns](/preparing-your-models#revisor-table-columns) are updated on the Draft +record, and the Draft record is copied into the Published table. The examples below demonstrate various common use cases relating to publishing records. You may wish to review the [HasPublishing Trait](https://github.com/indracollective/laravel-revisor/blob/main/src/Concerns/HasPublishing.php) @@ -22,19 +22,9 @@ echo $page->isPublished(); // true ## Automatic Publishing on Created/Updated -To automatically publish records on creation/update, you can make use of the `publishOnCreated` and -`publishOnUpdated` methods. This can be useful in Admin Panels like FilamentPHP where you want to augment the default -save behaviour without having to override the save method. +By default, Revisor will NOT Publish a record when a Draft is created or updated. -```php -$page = Page::make([...]); -$page->publishOnCreated(); -$page->save(); - -echo $page->isPublished(); // true -``` - -To automatically publish records on Created/Updated **by default**, you can set the following in your +To automatically publish records on Created/Updated, you can set the following in your `config/revisor.php` file: ```php @@ -46,6 +36,18 @@ To automatically publish records on Created/Updated **by default**, you can set ... ``` +You can also override the default behaviour on a per-Model basis by using the `publishOnCreated` and `publishOnUpdated` methods which accept a boolean value. + +```php +$page = Page::make([...]); +$page->publishOnCreated(true); +$page->save(); + +echo $page->isPublished(); // true +``` + + + ## Retrieve the Published Record Revisor-enabled Models have a `publishedRecord` HasOne relationship, which allows you to retrieve the published record @@ -83,7 +85,7 @@ echo $page->isRevised(); // false ## Unpublish a Record Unpublishing a record deletes the record from its Published table, and sets the `is_published` column to false on the -Draft record and Version record. +Draft record and current Version record. ```php $page = Page::first(); @@ -95,6 +97,6 @@ echo $page->isPublished(); // false ::: info NOTE The `unpublish` method must be called on the Draft record. While this may seem counter-intuitive, the reason is to maintain a one way flow, where the state of Published and Version records are always determined by the "main" Draft -record, effectively making them read-only artifacts of the Draft record. +record, effectively making them read-only artifacts of the state of, and actions performed on the Draft record. ::: diff --git a/docs/versioning.md b/docs/versioning.md index eeb91d6..298a050 100644 --- a/docs/versioning.md +++ b/docs/versioning.md @@ -34,8 +34,7 @@ To take more control of when new Version records are created, you can disable au ... ``` -You can also override the default behaviour on a per-model basis by using the `saveNewVersionOnCreated` and -`saveNewVersionOnUpdated` methods which accept a boolean value. +You can override the default behaviour on a per-Model basis by using the `saveNewVersionOnCreated` and `saveNewVersionOnUpdated` methods which accept a boolean value. ```php // config.revisor.versioning.save_new_version_on_created = false @@ -65,7 +64,7 @@ $page->saveNewVersion(); echo $page->versions()->count(); // 2 ``` -To update the current Version record rather than creating a new Version record, you can call the +To sync the current Version record with the Draft rather than creating a new Version, you can call the `syncToCurrentVersionRecord()` method on the Draft record. ```php @@ -76,7 +75,7 @@ $page->update([...])->syncToCurrentVersionRecord(); ## Retrieving Version Records -Get all Versions for a Draft or Published record via the `versionRecords` `HasMany` relationship. +Get all Versions of a Draft or Published record via the `versionRecords` `HasMany` relationship. ```php $page->versionRecords; diff --git a/src/Filament/PublishStatusTableColumn.php b/src/Filament/PublishStatusTableColumn.php deleted file mode 100644 index 16bd64a..0000000 --- a/src/Filament/PublishStatusTableColumn.php +++ /dev/null @@ -1,33 +0,0 @@ -label('Status') - ->badge() - ->getStateUsing(function (HasRevisor $record) { - if (! $record->isPublished()) { - return 'draft'; - } - - return $record->isRevised() ? 'published,revised' : 'published'; - }) - ->separator(',') - ->color(fn (string $state): string => match ($state) { - 'revised' => 'warning', - 'published' => 'success', - 'draft' => 'gray', - }); - } -} diff --git a/src/Revisor.php b/src/Revisor.php index 7f8fc85..6eabbf1 100755 --- a/src/Revisor.php +++ b/src/Revisor.php @@ -54,24 +54,24 @@ public function createTableSchemas(string $baseTableName, Closure $callback): vo } /** - * Amends 3 tables for the given baseTableName: + * Alters 3 tables for the given baseTableName: * - {baseTableName}_versions, which holds all the versions of the records * - {baseTableName}_live, which holds the published version of the records * - {baseTableName}, which holds the base data / drafts of the records */ - public function amendTableSchemas(string $baseTableName, Closure $callback): void + public function alterTableSchemas(string $baseTableName, Closure $callback): void { - // amend the versions table + // alter the versions table Schema::table(static::getVersionTableFor($baseTableName), function (Blueprint $table) use ($callback) { $callback($table, RevisorContext::Version); }); - // amend the published table + // alter the published table Schema::table(static::getPublishedTableFor($baseTableName), function (Blueprint $table) use ($callback) { $callback($table, RevisorContext::Published); }); - // amend the draft table + // alter the draft table Schema::table(static::getDraftTableFor($baseTableName), function (Blueprint $table) use ($callback) { $callback($table, RevisorContext::Draft); }); diff --git a/tests/MigrationsTest.php b/tests/MigrationsTest.php index 8bddd01..2afb6d3 100644 --- a/tests/MigrationsTest.php +++ b/tests/MigrationsTest.php @@ -5,8 +5,8 @@ use Illuminate\Support\Facades\Schema; use Indra\Revisor\Facades\Revisor; -it('creates and amends revisor schemas', function () { - // table creation and amendments in TestCase.php +it('creates and alters revisor schemas', function () { + // table creation and alterments in TestCase.php // assert that expected tables exist expect(Schema::hasTable(Revisor::getDraftTableFor('pages')))->toBeTrue() diff --git a/tests/TestCase.php b/tests/TestCase.php index 75a392d..8df5727 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -55,8 +55,8 @@ protected function setUpDatabase(): void $table->timestamps(); }); - // amend test tables - Revisor::amendTableSchemas('pages', function (Blueprint $table): void { + // alter test tables + Revisor::alterTableSchemas('pages', function (Blueprint $table): void { $table->string('content')->nullable(); }); }