Laravel Nova HTML editor: use Trix and account for its attachment files

In Laravel Nova, use a Trix field when an administrator needs to edit formatted content stored as HTML. A textarea holds source characters; Trix supplies the rich text interface. If the content includes uploaded images, the database field and those image files need separate attention.

Consider an invented equipment note called “Projector setup.” Its instruction belongs in the record's body column. A photograph showing the cable connection belongs on the configured storage disk, with the HTML referring to it. Saving one does not mean you have backed up the other.

Add the field to the resource

In an existing Nova 5 resource, this field definition maps the label “Body” to the model's body attribute:

use Laravel\Nova\Fields\Trix;

// Inside the resource's fields definition:
Trix::make('Body', 'body')->alwaysShow(),

Use an appropriate text column for the HTML. alwaysShow() affects the detail page's display, where Nova otherwise puts the content behind a reveal link. It does not change the storage format. The Nova field documentation defines this behavior.

If the page is meant to edit raw HTML source, choose an appropriate code-editing field instead. Trix edits a document through its supported formatting model. It is not a whole website editor for arbitrary scripts, stylesheets, and layout.

Choose the image disk deliberately

When administrators must drag photos into this field, Nova documents withFiles() with a filesystem disk name:

Trix::make('Body', 'body')
    ->withFiles('public')
    ->alwaysShow(),

Here public is a deliberate choice for images that the intended readers may access publicly. Do not select it for confidential equipment details merely because it appears in a sample. Your existing application needs an access design that fits the document and its files.

For Laravel's local public disk, the standard arrangement stores files under storage/app/public. The usual storage:link command creates the link used to serve that directory. Laravel's filesystem documentation explains disk configuration, URLs, and the public link. Other drivers and deployments need their own configuration.

A missing image can therefore have several causes: the file was never uploaded, the disk differs between environments, the public link is absent, or the stored URL no longer reaches the file. Read the failed image request before changing the editor field.

Include abandoned uploads in maintenance

Nova tracks pending and persisted field attachments in nova_pending_field_attachments and nova_field_attachments. Its installation migrations create those tables. A photograph uploaded to a form that the administrator abandons can remain pending.

Nova supplies a pruning job for stale pending attachments. Its documented scheduling fragment belongs in routes/console.php:

use Illuminate\Support\Facades\Schedule;
use Laravel\Nova\Fields\Attachments\PruneStaleAttachments;

Schedule::call(new PruneStaleAttachments)->daily();

Registering that schedule does not run it by itself. Confirm that the application's scheduler is operating in the deployed environment. Laravel's scheduling guide explains the server-side runner. Review the job's behavior and your retention requirements before enabling it on an existing system.

Reopen one saved note before migrating a collection

Use a disposable record in your development environment. Enter “Connect the blue cable before powering on,” attach the connection photo, and save. Reopen the record and inspect both the sentence and the actual image URL. Then change “blue” to the correct cable label, save again, and verify that the reader view contains the correction.

For the abandoned-form case, inspect the pending attachment record and its file under your application's test procedure. Do not use deletion against production attachments as an informal editor test. These steps are checks for your Nova application; the configuration fragments here do not demonstrate a running upload service.

The rich text editor introduction explains why document structure and plain text are different outputs. Nova adds a database and attachment lifecycle to that distinction. Back up the saved HTML, attachment records, and required files together so restoring the equipment note also restores the photograph it needs.

Keep reading