Contents

Laravel

The veditor/laravel package adds a Blade directive, routes for the editor files and the AI endpoint, and a service that sanitizes content before saving. It supports Laravel 11–13 (tested with Laravel 12) and PHP 8.2+.

VEditor in the Laravel test application

Installation

composer require veditor/laravel
php artisan vendor:publish --tag=veditor-config     # config/veditor.php

The service provider registers itself (extra.laravel.providers). Add the keys to .env:

VEDITOR_LICENSE_KEY="VED1.…"
OPENAI_API_KEY="…"          # AI edition with OpenAI (default)
# or Claude: the model selects the provider, only its key is needed
# VEDITOR_AI_MODEL=claude-sonnet-5-5
# ANTHROPIC_API_KEY="…"

Routes

RouteNameMiddleware
GET /veditor/assets/{version}/{file}veditor.assetconfig('veditor.routes.assetsMiddleware'), none by default
POST /veditor/aiveditor.aiconfig('veditor.routes.middleware'), ['web', 'auth'] by default

The assets route serves only .js and .css files from the package’s assets/ directory, with a one-year cache; the version in the address changes with every update. Change the prefix with routes.prefix.

Form

<form method="post" action="{{ route('articles.update', $article) }}">
    @csrf
    @method('PUT')
    @veditor('content', old('content', $article->body), ['height' => '400px'])
    <button>Save</button>
</form>

@veditor(name, value, options) renders the editor’s styles, a <textarea> with the content and a module script with the options from config/veditor.php merged with the third argument. It is a directive rather than a Blade component, so the article content never goes through the Blade compiler ({{ in the text stays text).

The script gets the nonce from Vite::cspNonce() when you use Laravel’s CSP support.

The third argument takes any editor option, for example a short toolbar for comments (item names in Editor options):

@veditor('comment', old('comment'), ['toolbar' => ['bold', 'italic', 'link', '|', 'bulletedList', 'numberedList', '|', 'undo', 'redo'], 'height' => '150px'])

A toolbar for every editor goes into editor in config/veditor.php.

Saving

use VEditor\Laravel\VEditorService;

public function update(Request $request, Article $article, VEditorService $veditor)
{
    $this->authorize('update', $article);
    $article->body = $veditor->sanitize($request->input('content'));   // LengthException above maxLength
    $article->save();

    return redirect()->route('articles.edit', $article);
}

sanitize() uses the styles from the configuration, the same ones the editor shows in its “Style” list.

Configuration

KeyDescription
routes.prefix, routes.middleware, routes.assetsMiddlewareroutes of the package
licenseKeyfrom VEDITOR_LICENSE_KEY
languageeditor language, from VEDITOR_LANGUAGE; null = app()->getLocale()
styles[['name' => 'Lead', 'element' => 'p', 'classes' => ['lead']]] for the editor and the sanitizer
editorother editor options, see Editor options
filePickerUrlyour file manager window, opened with VEditor.createIframePicker
uploadUrl, uploadFieldupload endpoint for dropped images, used by VEditor.createUploader
aiProvider, aiApiKey, aiAnthropicKey, aiEndpoint, aiAnthropicEndpoint, aiTextModel, aiTimeout, aiMaxRequest, aiContext, aiActions, aiFeaturesas in the server configuration
aieditor-side AI options, e.g. ['autocomplete' => true]

Without the API key of the chosen model’s provider (ANTHROPIC_API_KEY for a claude-… model, OPENAI_API_KEY for any other) the editor shows no AI buttons. Environment variables read by config/veditor.php: VEDITOR_LICENSE_KEY, VEDITOR_LANGUAGE, VEDITOR_AI_PROVIDER, OPENAI_API_KEY, ANTHROPIC_API_KEY, VEDITOR_AI_ENDPOINT, VEDITOR_AI_ANTHROPIC_ENDPOINT and VEDITOR_AI_MODEL. See Supported AI models.

Editor options are merged in this order, later ones win: language, licenseKey and styles, then ai, then editor, then the third argument of @veditor.

Roles and limits

In AppServiceProvider::boot():

use Illuminate\Support\Facades\RateLimiter;
use VEditor\Laravel\VEditorService;

$veditor = app(VEditorService::class);
$veditor->aiFeaturesUsing(fn ($user) => $user?->is_admin ? null : ['transform', 'review']);
$veditor->beforeAiRequestUsing(fn (string $feature, array $data) =>
    RateLimiter::attempt('veditor-ai:' . auth()->id(), 200, fn () => true, 86400) ?: 'Daily AI limit reached.');

Streaming

Transformations and the chat are streamed (text/event-stream). The controller saves and releases the session before streaming, so other requests of the same user are not blocked. Behind nginx, X-Accel-Buffering: no is sent; with Apache, mod_deflate is disabled for the response.

Showing the content

<link rel="stylesheet" href="{{ app(\VEditor\Laravel\VEditorService::class)->assetsUrl() }}/veditor-content.css">

<div class="veditor-content">{!! $article->body !!}</div>

Output the stored HTML unescaped only because it was sanitized on save.

Something unclear? Send feedback on the documentation.