Laravel validation attributes “nice names”

后端 未结 10 1807
[愿得一人]
[愿得一人] 2020-12-02 05:41

I\'m trying to use the validation attributes in \"language > {language} > validation.php\", to replace the :attribute name (input name) for a proper to read name (example: f

10条回答
  •  广开言路
    2020-12-02 06:25

    Well, it's quite an old question but I few I should point that problem of having the language appearing at the URL can be solved by:

    • Changing the language and fallback_language at config/app.php;
    • or by setting \App::setLocale($lang)

    If needed to persist it through session, I currently use the "AppServiceProvider" to do this, but, I think a middleware might be a better approach if changing the language by URL is needed, so, I do like this at my provider:

        if(!Session::has('locale'))
        {
            $locale = MyLocaleService::whatLocaleShouldIUse();
            Session::put('locale', $locale);
        }
    
        \App::setLocale(Session::get('locale'));
    

    This way I handle the session and it don't stick at my url.

    To clarify I'm currently using Laravel 5.1+ but shouldn't be a different behavior from 4.x;

提交回复
热议问题