Home > Enterprise >  Laravel 8.5's Validation is not working and getting an error
Laravel 8.5's Validation is not working and getting an error

Time:07-04

enter image description hereI am just calling an API with one array parameter with the required validation. But I am getting always an error message. The weird thing is that it has been working since I created the project but it suddenly stopped working today. I also cleared config:cache and apply the composer dumpautoload command till the issue remains the same.enter image description here

CodePudding user response:

first, try to dump all the input data using dd helper and see if the input format is correct so in the first line of your function dump it like below the check the output

dd( $request );

secondly, use the validate function of $request object so instead of calling and using Validator class, call it on the request object at the very first line of your function

$request ->validate([
    'booking_data' => 'required|array'
]);

and you don't need to manually check any validation and manually return something, it will automatically throw an error if it fails

  • Related