Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Remove attributes from the language file #37

Open
lhsazevedo opened this issue Oct 7, 2020 · 0 comments
Open

Remove attributes from the language file #37

lhsazevedo opened this issue Oct 7, 2020 · 0 comments

Comments

@lhsazevedo
Copy link

By default, Laravel's validation messages include the attribute name, contrary to the backend specification.

This was achieved by removing the first two words of each error message during runtime, instead of editing the language file directly.

$validationErrors = array_map(function($error) {
return array_map(function($message) {
return remove_words($message, 2);
}, $error);
}, $validationErrors);
return response()->json(['errors' => $validationErrors], 422);

Besides being unnecessary, this is a bad practice because, depending on the language, the name of the attribute will not necessarily be in the first two words.

The removal of attributes was even proposed by Laravel-Lang.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant