diff --git a/resources/boost/guidelines/core.blade.php b/resources/boost/guidelines/core.blade.php new file mode 100644 index 0000000..6812cf8 --- /dev/null +++ b/resources/boost/guidelines/core.blade.php @@ -0,0 +1,98 @@ +## Laravel Drafts + +A simple, drop-in drafts/revisions system for Laravel Eloquent models. + +### Features + +- Drafts and revisions for any Eloquent model via a single trait. +- Schema helper macros to add or remove required columns. +- Query scopes for published, drafts, and current revisions. +- Preview mode and middleware for draft access. + +### Installation + +@verbatim + +composer require oddvalue/laravel-drafts +php artisan vendor:publish --tag="drafts-config" + +@endverbatim + +### Required model setup + +- Add the `HasDrafts` trait to the model. +- Ensure the model table has the draft columns (use the schema macros). +- Optionally define `$draftableRelations` if you want relations copied/synced on publish. + +@verbatim + +use Illuminate\Database\Eloquent\Model; +use Oddvalue\LaravelDrafts\Concerns\HasDrafts; + +class Post extends Model +{ + use HasDrafts; + + protected array $draftableRelations = [ + 'tags', + ]; +} + +@endverbatim + +@verbatim + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Schema; + +Schema::table('posts', function (Blueprint $table) { + $table->drafts(); +}); + +@endverbatim + +### Creating drafts and publishing + +- New records are published by default. +- Use `createDraft`, `saveAsDraft`, or `updateAsDraft` to keep the published record unchanged. + +@verbatim + +Post::createDraft(['title' => 'Draft title']); + +$post = Post::create(['title' => 'Live title']); +$post->updateAsDraft(['title' => 'Draft edit']); + +@endverbatim + +### Querying revisions + +@verbatim + +$published = Post::withoutDrafts()->get(); +$withDrafts = Post::withDrafts()->get(); +$draftsOnly = Post::onlyDrafts()->get(); +$current = Post::current()->get(); + +@endverbatim + +### Preview mode and middleware + +@verbatim + +use Oddvalue\LaravelDrafts\Facades\LaravelDrafts; + +LaravelDrafts::previewMode(); +LaravelDrafts::disablePreviewMode(); + +@endverbatim + +@verbatim + +use Oddvalue\LaravelDrafts\Http\Middleware\WithDraftsMiddleware; + +Route::withDrafts(function (): void { + Route::get('/posts/publish/{post}', [PostController::class, 'publish']); +}); + +@endverbatim