PHP code example of degrinthorst / livewire-cms-editor

1. Go to this page and download the library: Download degrinthorst/livewire-cms-editor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

degrinthorst / livewire-cms-editor example snippets


// config/cms-editor.php  (driven by .env)
'columns' => [
    'json' => env('CMS_EDITOR_JSON_COLUMN', 'body'),   // source of truth, cast to array
    'html' => env('CMS_EDITOR_HTML_COLUMN'),            // null = render on the fly
],

use Degrinthorst\CmsEditor\Concerns\AdoptsEditorMedia;
use Degrinthorst\CmsEditor\Concerns\InteractsWithEditorMedia;
use Degrinthorst\CmsEditor\Contracts\HasEditorMedia;
use Spatie\MediaLibrary\InteractsWithMedia;

class Article extends Model implements HasEditorMedia
{
    use InteractsWithMedia;
    use InteractsWithEditorMedia;
    use AdoptsEditorMedia; // claims inserted images on save (recommended)

    public function registerMediaCollections(): void
    {
        $this->registerEditorMediaCollection();
    }

    protected $casts = ['body' => 'array']; // ProseMirror JSON (ADR-003)
}

app(\Degrinthorst\CmsEditor\Support\ContentRenderer::class)->toHtml($article->body);

$this->app->bind(
    \Degrinthorst\CmsEditor\Support\ContentSanitizer::class,
    YourPurifierSanitizer::class,
);
bash
php artisan vendor:publish --tag=cms-editor-config
php artisan vendor:publish --tag=cms-editor-assets   # pre-built JS into public/vendor/cms-editor
blade
{{-- inside a Livewire form component with a public array $body --}}
<x-cms-editor wire:model="body" :model="$article ?? null" />
bash
php artisan cms-editor:prune-orphans --dry-run     # preview
php artisan cms-editor:prune-orphans --ttl=7 --force  # delete, sparing bucket uploads < 7 days