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

jkew's avatar
Level 1

Thanks,

I already change the code in the PaymentController storeUserInfo() method and the ajax in the payment.blade.php like below but Im getting {↵ "message": "Unresolvable dependency resolving [Parameter #1 [ array $data ]] in class Illuminate\Validation\Validator".

// storeUserInfo() method

public function storeUserInfo(Request $request, $id, $slug = null, Validator $validator){
//dd($request);
$request->validate([
'name' => 'required|max:255|string',
'surname' => 'required|max:255|string',
...
]);

if ($validator->fails()) {

if($request->ajax())
{
return response('test');
}

$this->throwValidationException(

$request, $validator

);

} 
// ajax in payment.blade.php
$('#goToStep2').on('click', function (event) {
        event.preventDefault();

        var custom_form = $("#" + page_form_id);

        $.ajax({
            method: "POST",
            url: '{{ route('products.storeUserInfo',$id) }}',
            data: custom_form.serialize(),
            datatype: 'json',

            success: function (data, textStatus, jqXHR) {
                setTimeout(function () {

                }, 3000);
            },
            error: function (data) {
                console.log(data);
                var errors = data.responseJSON;
                var errorsHtml = '';
                $.each(errors['errors'], function (index, value) {
                    errorsHtml += '<ul class="list-group"><li class="list-group-item alert alert-danger">' + value + '</li></ul>';
                });

                $('#response').show().html(errorsHtml);
            }
        });

        });
    });

Snapey's avatar

you dont need to mess about redirecting in ajax

ok, see the method presentPaymentPage. you are passing id and slug to the view. You can therefore use these in your route.

url: '{{ route('products.storeUserInfo', $id, $slug) }}'

you will now be able to POST the data to the correct route and move on to the next problem

1 like
Snapey's avatar
Snapey
Best Answer
Level 122

you are missing the slug. I had an error in my previous reply. the second parameter needs to be an array, or remove the slug from the POST route

url: '{{ route('products.storeUserInfo', compact('id','slug') ) }}'
1 like
Snapey's avatar

ok, so now you need to decide what you are doing at each step.

You have posted the data, validated it, then what? Are you going to store the data from step 1?

One thing for sure, you cannot return a redirect.

1 like
jkew's avatar
Level 1

No, the ajax request in step 1 is just to validate, and if all data is valid the user should go to the step 2 otherwise it should appear the respective validation error. In step 2 the same. Then in step 3 is necessary to insert some stuff in the database.

Snapey's avatar

ok, first problem, you need to track what step you are on.

next problem is that in step 2 you will have the data from step 1 and the data from step2. plus you will need another route with another set of validation rules.

Then in step 3 you will have yet another route and then all the valudation rules again because you cannot trust that the user did not skip validation by just going straight to step 3

Ijust cant see this all working out for you.

At this stage, step 1, you just need to return a 200 code if data is valid.

By the way, you know you can just validate the data in the client?

1 like
jkew's avatar
Level 1

Thanks, when you are saying track the step can you explain a little better? That is to solve the 500 internal server error?

Snapey's avatar

Go back to your original code but replace the last line

public function storeUserInfo(Request $request, $id, $slug = null){
        //dd($request);
        $request->validate([
            'buyer_name' => 'required|max:1|string',
            'buyer_surname' => 'required|max:255|string',
            'buyer_email' => 'required|max:255|email',
            'name_invoice' => 'required|max:255|string',
            'country_invoice' => 'required|max:100|string',
        ]);

    return ;

    }
1 like
jkew's avatar
Level 1

Thanks, I already remove the return. I have it like below but it appears the internal server error even without the return:

// storeUserInfo() method

public function storeUserInfo(Request $request, $id, $slug = null, Validator $validator){
//dd($request);
$request->validate([
'name' => 'required|max:255|string',
'surname' => 'required|max:255|string',
...
]);

if ($validator->fails()) {

if($request->ajax())
{
return response('test');
}

$this->throwValidationException(

$request, $validator

);

} 
Snapey's avatar

look at your code. How does $validatorcontain the result of your validation?

1 like
jkew's avatar
Level 1

Thanks, I change the code to:

$validator = Validator::make($request->all(),[
            'buyer_name' => 'required|max:255|string',
            'buyer_surname' => 'required|max:255|string',
            'buyer_email' => 'required|max:255|string',
            'name_invoice' => 'required|max:255|string',
            'country_invoice' => 'required|max:255|string',
        ]);

But I get the same 500 error.

Cronix's avatar

Have you looked at your error logs to see what the error actually is coming from?

Previous

Please or to participate in this conversation.