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);
}
});
});
});
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
Thanks! Like that it appears a "//" after the product id instead of "/" and because of that a 404 error:
POST http://store.test/product/1//payment/StoreUserInfo 404 (Not Found)
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') ) }}'
Thanks! Now it appears again: jquery.min.js:4 POST http://store.test/product/1/product-test/payment/storeUserInfo 500 (Internal Server Error) and "return response('test');" in the storeUserInfo() controller method shows: "Unresolvable dependency resolving [Parameter #1 [ array $data ]] in class Illuminate\Validation\Validator".
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.
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.
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?
Thanks, when you are saying track the step can you explain a little better? That is to solve the 500 internal server error?
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 ;
}
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
);
}
look at your code. How does $validatorcontain the result of your validation?
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.
Have you looked at your error logs to see what the error actually is coming from?
Please or to participate in this conversation.