This repository was archived by the owner on Sep 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
Remove attributes from the language file #37
Copy link
Copy link
Open
Description
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.
laravel-realworld-example-app/app/Exceptions/Handler.php
Lines 93 to 99 in 86128fc
$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.
Metadata
Metadata
Assignees
Labels
No labels