inertiajs / inertia-laravel

The Laravel adapter for Inertia.js.
https://inertiajs.com
MIT License
2.09k stars 235 forks source link

Laravel error messages are not showing properly #216

Closed mrlinnth closed 3 years ago

mrlinnth commented 3 years ago

2021-02-19_15-09

My controller

        $request->validate([
            'title' => ['required','min:20'],
            'body' => ['required','min:20'],
            'email' => ['required','email'],
        ]);

I followed the documentation for the validation. The error messages are shared to Vue from Laravel but the messages are not shared. Only the index of the error messages are shared I think.

Am I missing something?

claudiodekker commented 3 years ago

Hi,

What's being shared in this case, is the translation key: https://github.com/laravel/laravel/blob/ebf2646c347b941e63709f7e69ab79416f6d5124/resources/lang/en/validation.php#L90

By default, a standard Laravel & Inertia setup does share this correctly in my experience, so it's quite likely that you changed something in the default localization setup that's causing this. A good example of this, is that you're using a (different) app locale for which you don't have the correct translations (any longer).

Although I'm fairly certain this isn't a problem caused by Inertia's involvement in your app, it's best to confirm this for yourself by re-creating this situation within a Blade view. If my suspicion is correct, you'd still see the untranslated language key in that situation, even though Inertia isn't being used. Of course, that wouldn't solve your issue, but at the very least it leads you closer to the actual problem, which is all that I can do with the current context/information.

Hope this helps!

mrlinnth commented 3 years ago

Spot on, mate. Thank you so much. I forgot that I (carelessly) deleted the default lang/en folder.

claudiodekker commented 3 years ago

Glad you solved it! 👍