Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Error Message Laravel Package

tsungsoft/error-message

A lightweight Laravel package for managing and returning consistent error messages. Simplify validation and API error responses with helpers that keep your output uniform across controllers, exceptions, and JSON endpoints.

View on GitHub
Deep Wiki
Context7

Getting Started

Install via Composer, then register the field inside a Nova resource's fields() method. The package is a Nova field, not middleware or a validation library, so there is nothing to publish or configure before first use beyond the Composer require.

composer require tsungsoft/error-message
// app/Nova/User.php
use Tsungsoft\ErrorMessage\ErrorMessage;

public function fields(NovaRequest $request)
{
    return [
        ErrorMessage::make('Validation note')
            ->withMeta(['message' => 'This record is locked until review.']),
        // ...rest of your fields
    ];
}

Where to look first:

  • src/ — the field class itself (namespace Tsungsoft\ErrorMessage, class likely ErrorMessage or Field). Confirm the exact class and make() signature before wiring it up.
  • The field's component() method — it tells you which Vue component name Nova will render. That name must match the .vue file registered in the package's resources/js/field.js (or its compiled asset).
  • README.md and the package's dist/js — with only 2 stars and a 2019 release date, the README is often the only accurate source of truth for constructor arguments and meta keys.

First use case: surface a server-side validation or business-rule message inline in a Nova detail/edit form, where Nova's own validation banners don't reach (e.g. a message computed in fields() from the model's state). It is best treated as a presentational, read-only field — you control the string, the field renders it.

Implementation Patterns

Static informational field. The most reliable pattern: construct the field with a message derived from the resource in fields(). Because fields() receives NovaRequest, you get access to $request->resource() (the underlying model id) and can read the model before building the field.

$user = $request->resource() ? User::find($request->resource()) : null;

ErrorMessage::make('Status')
    ->withMeta([
        'message' => $user?->is_locked
            ? 'Account locked — edits are queued for approval.'
            : '',
    ])
    ->hideWhenCreating(); // only meaningful in edit context

Conditional visibility instead of conditional rendering. If the package's Vue component always outputs a container, prefer ->hideWhenCreating(), ->hideFromIndex(), ->hideFromDetail(), or ->onlyOnForms() to keep the message out of contexts where it makes no sense. This is cheaper than trying to patch the Vue component.

Companion to dependsOn. If you use Nova's dependsOn() on sibling fields to push live values down to the message field, be careful: dependsOn resolves other fields' current values client-side, so the target field receives them through meta. That requires the field's Vue component to react to field.value / prop changes — verify the bundled component does, otherwise the message will not update until save. When in doubt, use resolveUsing on the server rather than dependsOn.

Pairing with resource tooling. A practical split that ages well: keep validation rules in the FormRequest, and use this field purely as a display surface for messages those rules generate (custom rule classes that stash a reason on the model, or a getValidationMessage() accessor). That keeps the field dumb and the logic testable.

Integration tip — placement. Put the field at the top of the form array so the message appears above the inputs. Nova renders fields in declared order; a field declared last will sit at the bottom near the "Update" button, which is where users look for global errors, but not for per-field guidance.

Gotchas and Tips

Nova version compatibility is the main risk. Released 2019-10-31, this targets Nova 2.x/3.x with Vue 2 tooling. Nova 4 and 5 changed the field class contract (NovaRequest, Field base class, nova.mix.js asset pipeline). Expect the PHP class to load but the JS component to fail on modern Nova. Test the field in isolation on your Nova version before decorating a resource.

Built assets may not match source. Nova packages ship a compiled dist/js/field.js. If the compiled asset is stale or built against an old Nova, editing the .vue file will do nothing until you recompile. Check composer.json for a scripts entry (or package.json for npm run dev / npm run prod), and if the package has no build script, you will need to add the component to your app's own Nova asset pipeline.

The meta key name is not guaranteed. The example above assumes message. If the Vue component reads field.message or field.errorText instead, the field will render empty with no error. In practice, verify by inspecting the component's props and its field template bindings in resources/js/components/. This is the single fastest debugging step.

Empty messages can leave dead whitespace. Fields that render a wrapper <div> will still take vertical space with an empty string. If the component doesn't handle falsy values, gate on hideWhen...() server-side rather than passing ''.

Debugging checklist, in order: (1) php artisan nova:asset / npm run production in the package or your app; (2) check the browser console for a missing Vue component name — Nova logs "Failed to mount component" with the registered name; (3) dd() inside fields() to confirm the meta actually reaches the field; (4) confirm component() returns a name that exists in app.js.

Extension points. The cleanest long-term move with a package this small is to copy it: the field is a thin PHP class plus one Vue component. Vendor a copy into nova-components/error-message/ and you own the build pipeline, the message-prop naming, and Nova-version upgrades — which removes the 2019-asset risk entirely. Only keep the Composer dependency if you are pinned to the same Nova major as the package.

Don't use it for validation. It cannot abort a save and it does not integrate with FormRequest. For real validation messages use Laravel's validation helpers; reserve this field for advisory text and server-computed status messages.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
frankyso/ipaymu
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
adachsoft/api-version-bundle
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core