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

ankurdhawan's avatar

Validation Failure is throwing array_replace_recursive() error

Hi, I am getting the following error array_replace_recursive(): Argument #2 must be of type array, int given at \vendor\laravel\framework\src\Illuminate\Translation\FileLoader.php: 129

Whenever my validation is failing. I have tried all the methods. My Validation logic is as follows:

$request->validate([ 'user_id' => 'required', ]);

I have banged my head everywhere. But no solution is found.

Please help.

Thanks, Ankur

0 likes
11 replies
Tray2's avatar

You need to share a bit more code than that fro us to be able to even guess at what the problem is.

ankurdhawan's avatar

public function createNp(Request $request){ $validated = $request->validate([ 'user_id' => 'required', ]);

    $ifCreated = $this->npService->createNP($request);

    if($ifCreated) {

        // Send Push notification

        return redirect()->back()->withSuccess('NP initiated successfully');
    } else {
        return redirect()->back()->withErrors('User already having NP');
    }
}

I am sending user_id = null to check if validation is working or not. But it is throwing error. When I send valid user_id, everything works smoothly. No error is observed.

ankurdhawan's avatar

I have checked in the code at the places where it was working earlier. At the initial stages of my project, Laravel validations was working fine. After that, at those places nothing has been changed.

But now, validation is throwing same error at those places as well. So it seems there is no issue here with this code. But at some other place. And now I am totally blind where to look for.

Please help.

Thanks, Ankur

Tray2's avatar

@ankurdhawan Your code makes little sense to me, but try changing this line

$validated = $request->validate([ 'user_id' => 'required', ]

To this

$validated = $request->validate([ 'user_id' => ['required'], ]
ankurdhawan's avatar

Hello @tray2 ,

I have already tried this. But no gain. :(

Now I am commenting validations in all my code and will activate very first only validation that I wrote and will check if it is working or not. As that was working at that time.

Tray2's avatar

@ankurdhawan if the validation fails, then you are sent back to the page you came from, so maybe there is something wrong there.

ankurdhawan's avatar

@Tray2 I just commented validation at all pages. And kept only the very first validation which was working. But it is also not working now. This page has not been changed from starting

I am posting my html content here.

@if ($errors->any()) @foreach ($errors->all() as $error) {{ $error }} @endforeach @endif

Tray2's avatar

@ankurdhawan You need to share all the code, the routes, the controller, the model, and any other related code.

ankurdhawan's avatar

@Tray2 Please share your email id so that I can mail you the files.

Files are bit larger ... so wont be able to post here ....

ankurdhawan's avatar

Issue is resolved.

Actually my lang folder was outside resources. So I moved my lang/en complete folder inside resources and it worked.

@tray2 Thanks for your time.

Please or to participate in this conversation.