dij-digital/deconstructed-validation-messages

1.1 2024-08-07 09:15 UTC

This package is auto-updated.

Last update: 2024-11-07 09:51:28 UTC


README

Is your application headless or an API? Do you want all your translations to be done in the frontend? Then this is the package for you. Instead of returning the translated error strings from the Laravel translation files, this package returns the original translation keys, the parameters and their values.

Installation

You can install the package via composer:

composer require dij-digital/deconstructed-validation-messages

Optionally you can publish the config file with:

php artisan vendor:publish --tag="deconstructed-validation-messages-config"

This is the contents of the published config file:

return [
];

Usage

Simply install the package and make sure the provider is registered. The package will automatically take care of the rest.

Your response will look like this:

{
  "field": {
    "rule": {
      "key": "rule.language_key",
      "message": "Traditional error message",
      "parameters": {
        "x": 1,
        "y": 2
      }
    }
  }
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits