Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gzai's avatar
Level 3

laravel 9 validation error

Hello all,

I have validation, previously it was running correctly. But after that result becomes validation.required, even though I didn't change any settings.

Laravel 9.7.0

image : https://ibb.co/fpQCDhW

0 likes
30 replies
gzai's avatar
Level 3

I've checked, value is still same.

    'timezone' => 'UTC',

    /*
    |--------------------------------------------------------------------------
    | Application Locale Configuration
    |--------------------------------------------------------------------------
    |
    | The application locale determines the default locale that will be used
    | by the translation service provider. You are free to set this value
    | to any of the locales which will be supported by the application.
    |
    */

    'locale' => 'en',

    /*
    |--------------------------------------------------------------------------
    | Application Fallback Locale
    |--------------------------------------------------------------------------
    |
    | The fallback locale determines the locale to use when the current one
    | is not available. You may change the value to correspond to any of
    | the language folders that are provided through your application.
    |
    */

    'fallback_locale' => 'en',

and clear config still not working

php artisan config:clear
Sinnbeck's avatar

@gzai Check your en/validation.php file for the required key then. Its in your lang directory (either in /lang or /resources/lang. It was moved in laravel 9)

gzai's avatar
Level 3

lang/en/validation.php

    'regex' => 'The :attribute format is invalid.',
    'required' => 'The :attribute field is required.',
    'required_array_keys' => 'The :attribute field must contain entries for: :values.',
    'required_if' => 'The :attribute field is required when :other is :value.',

for directory :

root
-- lang
---- en
------ auth.php
------ pagination.php
------ passwords.php
------ validation.php
-- resources
---- lang
------ vendor
Sinnbeck's avatar

@gzai Can you try running dd(trans('validation.requried')); in a controller and see what you get?

gzai's avatar
Level 3

@Sinnbeck

^ "validation.requried"

I've tried deleting the vendor folder and reinstalling, but it still doesn't work

Sinnbeck's avatar

@gzai I honestly have no clue. I cannot recreate it in a laravel 9 project..

I dont suppose this is an opensource project so I can inspect the code on github ?

gzai's avatar
Level 3

thanks @Sinnbeck,

I will check again all my code. If I find the problem and fix it, I will let anyone know.

Sinnbeck's avatar

@gzai Are you sure its laravel 9 and not 8? If it was 8 it would not be able to find the /lang folder. Does your other translations work as expected?

Do you have an en.json file perhaps that is messing it up (you can try renaming it)

gzai's avatar
Level 3

@Sinnbeck , yeah I'm pretty sure its laravel 9

php artisan --version
Laravel Framework 9.7.0

composer.json

"require": {
        "php": "^8.0.2",
        "artesaos/seotools": "^0.22.0",
        "barryvdh/laravel-elfinder": "^0.5.1",
        "cybercog/laravel-ban": "^4.7",
        "guzzlehttp/guzzle": "^7.2",
        "jantinnerezo/livewire-alert": "^2.2",
        "jenssegers/agent": "^2.6",
        "laravel/framework": "^9.2",
        "laravel/jetstream": "^2.6",
        "laravel/sanctum": "^2.14.1",
        "laravel/socialite": "^5.5",
        "laravel/tinker": "^2.7",
        "livewire/livewire": "^2.5",
        "maatwebsite/excel": "^3.1",
        "mtvs/eloquent-hashids": "^3.2",
        "niklasravnsborg/laravel-pdf": "^4.1",
        "owen-it/laravel-auditing": "^13.0",
        "power-components/livewire-powergrid": "^2.4",
        "psr/simple-cache": "1.0",
        "pusher/pusher-php-server": "^7.0",
        "spatie/laravel-permission": "^5.5",
        "spatie/laravel-sitemap": "^6.1"
    },

Does your other translations work as expected? everything is not working as expected.

e.g. :

    $validated = $request->validate([
        'name' => 'required|numeric|max:255',
    ]);
// type input : abcde
// result : validation.numeric

after renaming en.json to fr.json and config:clear, it still doesn't work.

lang/en/en.json

{
    "The :attribute must contain at least one letter.": "The :attribute must contain at least one letter.",
    "The :attribute must contain at least one number.": "The :attribute must contain at least one number.",
    "The :attribute must contain at least one symbol.": "The :attribute must contain at least one symbol.",
    "The :attribute must contain at least one uppercase and one lowercase letter.": "The :attribute must contain at least one uppercase and one lowercase letter.",
    "The given :attribute has appeared in a data leak. Please choose a different :attribute.": "The given :attribute has appeared in a data leak. Please choose a different :attribute."
}

gzai's avatar
Level 3

@Sinnbeck yes, I only using translations for validation. it's so weird.

Sinnbeck's avatar

@gzai Is there anything in your service providers that could tamper with it? Check each one. Or a package that helps with translations somehow?

You dont by any chance have xdebug?

gzai's avatar
Level 3

@Sinnbeck this so weird.

I just copied en folder in lang folder, and pasted it into resources/lang folder, the result is as expected.

current structure :

root
--- lang
------ en
--------- auth.php
--------- pagination.php
--------- passwords.php
--------- validation.php
------ en.json
--- resources
------ lang
--------- en
------------ auth.php
------------ pagination.php
------------ passwords.php
------------ validation.php
--------- vendor

I compared the structure of laravel 9 (fresh install with same package list) with structure of my project using winMerge. no strange differences.

how is it possible to add en folder into resource/lang folder and the result can be as expected? it's very wrong in laravel 9 structure?

Snapey's avatar

@gzai This test didn't work because you spelled required incorrectly.

gzai's avatar
Level 3

@Sinnbeck yes, it's works now. but I have to copy en folder into resources/lang folder.

gzai's avatar
Level 3

@Sinnbeck , ah, I got it, why lang folder in root.

This error is because I publish Language file from livewire-powergrid package. if I delete lang folder in resources folder. it's works.

@snapey I still haven't found spelled required incorrectly.

1 like
Sinnbeck's avatar

@gzai awesome.

I misspelled it here

Can you try running dd(trans('validation.requried')); in a controller and see what you get?

gzai's avatar
gzai
OP
Best Answer
Level 3

@Sinnbeck

If I running this code in controller, with structure like this :

root
--- lang
--- resources
------ lang
--------- vendor
------------ livewire-powergrid
dd(trans('validation.required'));
// result 
^ "validation.required"

but, if I delete lang folder inside resources folder

root
--- lang
--- resources
dd(trans('validation.required'));
// result 
^ "The :attribute field is required."

it seems because the package hasn't changed the target publish language file yet into lang folder in root.

1 like
Sinnbeck's avatar

@gzai ah makes sense. I believe laravel checks both locations for now, so just leave it in the old location

gzai's avatar
Level 3

@Sinnbeck Looks like Laravel checks both locations, but it will be prioritized if found lang folder in resources folder.

Sinnbeck's avatar

@gzai yeah most likely for legacy reasons :) if it's working you can mark the thread as solved by marking a best answer

PhillipMwaniki's avatar

@gzai I had a similar problem a while ago and the issue was the lang directory in the resources folder. Deleted it and it went back to normal

base8innovations's avatar

Hey, came across this same issue and the only thing that worked was copying the lang folder to the resources folder (Laravel 9)

1 like

Please or to participate in this conversation.