Category : laravel-validation

I have made this form and added it to the Blade: <form role="form" action="{{ route(‘client.stepOne’) }}" method="POST" class="login-box" autocomplete="off"> @csrf <div class="row"> <div class="col-md-6"> <div class="form-group BHoma"> <label>Country:</label> <select class="form-select" aria-label="" disabled></object> <option value="ir" selected>ایران</option> </select> </div> </div> <div class="col-md-6"> <div class="form-group BHoma"> <label> <span class="required-input">*</span>&nbsp; Type phone number </label> <input autocomplete="off" class="form-control" name="phone" placeholder="مانند: ..

Read more

I have the following validation rule in which I need to sure that the streaming_platforms array includes the correct information. So the stream_key and stream_url are required if the enable key is true. The stream_key should be a string and stream_url should be a URL. $validator = Validator::make($input, [ ‘name’ => ‘required|string|min:3|max:255’, ‘type’ => ‘required|in:private,public’, ..

Read more

I am working on returning validation errors in multiple languages at the same time. I have a controller that injects a class that extends FormRequest and I am overriding ‘failedValidation’ and there I get the validator error messages. public function store(SysUserStoreRequest $request) { // … } class SystemUserStoreRequest extends ApiRequest { // This extends another ..

Read more

I’ve created a custom form request with php aritisan make:request, I have added in validation rules: public function rules() { return [ ‘first_name’ => ‘required|string’, ‘last_name’ => ‘required|string’, … ’email’ => ’email|unique:auth_user,email’, ‘password’ => [‘required’, ‘confirmed’, Password::min(8)], ‘password_confirmation’ => ‘required|string|min:8’, ]; } However, it redirects me to the index page. This is my function: public ..

Read more

Just started with my first PHP laravel project, and I have this UserRepository.php public function validateNewEmail(Request $request, $emailName) { $request->validate([ $emailName => [‘required’, ’email’, ‘unique:users’], ]); } public function validateNewPassword(Request $request, $passwordName) { $request->validate( // rule [ $passwordName => [‘required’, ‘min:8’, ‘regex: // some long long regex’ ], // message [ $passwordName.".regex" => "Your new ..

Read more

I am making the following call to my API routes using Postman everything works fine until I force a validation error. the error object returned doesn’t contain the full list of validation errors instead it only has something like this: {"message":"The given data was invalid.","errors":{"email":["validation.email"],"password":["validation.min.string"]}} What I want is that instead of "validation.min.string" it should ..

Read more

Is it possible to add validation if another validation passed for example I have the following validation rules return [ ‘name’ => [‘required’, ‘string’, ‘min:3’, ‘max:30’], ‘password’ => [‘required’, ‘min:6’], ‘photo’ => [‘imageable’], ‘business_uuid’ => [‘required’, ‘uuid’, ‘exists:businesses,uuid’], ]; and I would like if the business_uuid validation passed to add validation for the phone number ..

Read more

This is how my validator looks like public function addQuestions(Request $request, $quiz) { $request->validate([ ‘data.attributes.questions’ => ‘array’, ‘data.attributes.questions.*.question’ => ‘required|string’, ‘data.attributes.questions.*.type’ => ‘required|integer|exists:question_types,id’, ‘data.attributes.questions.*.options’ => ‘required|array’, ‘data.attributes.questions.*.options.*.aid’ => ‘required|string|distinct’ ]); … } Now as I have used distinct in data.attributes.questions.*.options.*.aid’ => ‘required|string|distinct’ it checks for whole request and returns validation error if it finds a ..

Read more

I am using FormRequest to validate data. I know this question was asked many times and community try to solve this issue in many ways but none of them solve my problem. Reference links are attached. In FormRequest class AbcRequest extends FormRequest { public function authorize(){ return true; } public function rules() { return [ ..

Read more

Please check below my validation rule. But it’s not working. I am sharing database table screen shot and error which getting. ‘section.2.model_of_vehicle’ => ‘required|exists:vehicles,model_name|in:Ford Transit, Ford Tourneo, Volkswagen Crafter, Mercedes Sprinter, Toyota Prius Hybrid, Volkswagen Caddy Maxi, Renault Master, Peugeot Boxer, Vauxhall Vivaro, Vauxhall Movano, Other’, Sourc..

Read more

I have a form where the user enters their education from Elementary to College. If they want to add any other studies they’ve done, they can click the "Add Other Studies" button, and a new set of input fields will appear for Other Studies {{– Button –}} <tr> <td scope="col"><button type="button" onclick="addOtherStudies()" name="add-educ-exp" id="ar-educexp" class="btn ..

Read more

I have a request in the format array:2 [▼ "_token" => "Lqn3XPvbdhLC8iqs461xSrGYPmxmSv4PGCqH7LJQ" "branch" => array:16 [▼ "customer_company_id" => "5" "is_main" => "true" ] ] I need to validate the form in the following way: If customer_company_id is present name is not required If customer_company_id is not present name is required My FormRequest looks like public ..

Read more

I use custom request classes which extend Laravavel’s FormRequest (User Guide, API Documentaion) in order to validate the input parameters, and to authorize the request. The skeleton looks like this: class MyRequest extends FormRequest { /** * Determines if the user is authorized to make this request. */ public function authorize(): bool { // TODO: ..

Read more

I’m facing a problem while validating the country in laravel 1.View <div class="form-group"> <label >{{__("Country")}} <span class="required">*</span> </label> <select name="country" class="form-control"> <option value="">{{__(‘– Select –‘)}}</option> @foreach(get_country_lists() as $id=>$name) <option @if((old(‘country’,$dataUser->country ?? ”)) == $id)selected @endif value="{{$id}}">{{$name}}</option> @endforeach </select> <span class="invalid-feedback error error-country"></span> </div> 2.in Controller ‘country’ => ‘required|max:200’, ‘country.required’ => __(‘Select your country from the ..

Read more

I need to validate a request account_type if it is either ‘Personal’ or ‘Organizational’ So that i can validate other field by required if account_type,personal.Heres the code that i have tried. ‘account_type’ => ‘required|options:PERSONAL,ORGANIZATIONAL’, ‘per_client_name’ => ‘required_if:account_type,PERSONAL|string’, ‘per_street’ => ‘required_if:account_type,PERSONAL’, ‘per_address’ => ‘required_if:account_type,PERSONAL’, ‘org_name’ => ‘required_if:account_type,ORGANIZATIONAL’, ‘org_type’ => ‘required_if:account_type,ORGANIZATIONAL’, ‘org_cont_name’ => ‘required_if:account_type,ORGANIZATIONAL’ Method IlluminateValidationValidator::validateOptions does ..

Read more

I got an input that contains an array of objects. Now I’d like to validate it, but one part of the validation depends on another item of the object, so I need it’s index: [ ‘items.myarray.*.owner_id’ => ‘numeric|exists:AppModelsOwner’, ‘items.myarray.*.key’ => [‘nullable’, ‘string’, ‘min:20’, ‘max:20’, ‘exists:AppModelsInvitation,key’, new KeyIsValid(Owner::findOrFail(request()->input(‘items.*.owner_id’)))], ]; Of course request()->input(‘items.myarray.*.owner_id’) is not working – ..

Read more