Category : validation

In my Laravel 8 project I have an existing global scope bind to a model like so: protected static function booted() { static::addGlobalScope(new CompanyScope()); } I already know that you can add a local scope to a validation rule like this: class ExpenseRequest extends FormRequest { protected function validationRules(): array { return [ "attachment" => ..

Read more

I am working on a laravel 8 application and using spatie/laravel-permission for roles and permissions. On the admin page, I’m displaying all users which the admin can do CRUD operations on. The users list also includes his own admin account. The problem I’m having is when updating user details. The admin can successfully update user ..

Read more

function validate i want to validate unit_amount[1], unit_amount[2],unit_amount[3]…..,unit_amount[n] .i only validate unit_amount[0], public static function rules($id = NULL) { return [ ‘target’ => ‘required|max:255’, ‘date_inventory’ => ‘required’, ‘type_amount’ => ‘required’, //id use when update with validate unique ‘number’ => ‘required|max:7|unique:inventories,number,’. $id, ‘day’ => ‘required’, ‘hour’ => ‘required’, ‘full_name’ => ‘required|max:150’, ‘title’ => ‘required|max:60’, ‘represent’ => ..

Read more

I have different inputs depends on radio buttons. How to validate them according to selection? <div class="sm:col-span-2"> <div class="mt-4"> <nav class=" " aria-label="Tabs"> <div class="border-gray-300 border-2 rounded-lg pl-3 py-2 w-40" :class="tab == ‘tab1’ ? ‘ bg-green-200 border-green-500 ‘ : ”"> <input type="radio" @click="tab = ‘tab1’" checked="tab == ‘tab1’ ? true: false" name="person_company"> <span class="text-gray-600 font-medium ..

Read more

I’m using a validator to validate user input in my Laravel 8.5x project. This is the code I use: use IlluminateSupportFacadesValidator; $validator = Validator::make([‘SelectedMonth’ => $SelectedMonth, ‘SelectedStartDate’ => $SelectedStartDate, ‘SelectedEndDate’ => $SelectedEndDate], [ ‘SelectedMonth’ => ‘required|max:7|regex:[^(d{4}-)?d{2}$]’, ‘SelectedStartDate’ => ‘nullable|max:12|regex:/^d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/’, ‘SelectedEndDate’ => ‘nullable|max:12|regex:/^d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/’ ]); if ($validator->fails()) { abort(404); } else {} It works great but the ..

Read more

Im using Laravel8, and I want to return the inputs after failed validation in the form. **VIEW: <div class="form-group"> <label>{{__("Coupon Code")}} <span class="text-danger">*</span></label> <input type="text" maxlength="50" required value="{{$row->code}}" placeholder="{{__("Unique Code")}}" name="code" class="form-control"> Controller: public function store( Request $request,$id ){ $request->validate([ ‘code’=>[ ‘required’, ‘max:50’, ‘string’, ‘alpha_dash’, Rule::unique(‘bravo_coupons’)->ignore($id > 0 ? $id : false) ], ‘amount’=>[‘required’], ]); ..

Read more

i’m having a hard time figuring out how to validate children of an array, depending on the child itself. To get the Idea, i coded some wished behaviour to illustrate the problem with the required_if rule return $flight_data = $request->validate([ ‘flights.*.ac_call’ => ‘required|string’, ‘flights.*.ad_dep’ => ‘required|string’, ‘flights.*.ad_dest’ => ‘required|string’, ‘flights.*.dep_date’ => ‘required_if:flights.*.ad_dep,VALUE|date_format:d.m.Y’, ‘flights.*.dep_time’ => ‘required_if:flights.*.ad_dep,VALUE|date_format:H:i’, ..

Read more

I’m using the Laravel PHP framework. Here’s an example of how we do validation: $rules = [ ‘name’ => ‘required|string|max:255’, ‘description’ => ‘nullable|string|max:255’ ]; $messages = [ ‘name.required’ => ‘The :attribute field is required.’, ‘name.max’ => ‘The maximum allowed length of :attribute is :max characters.’, ‘description.required’ => ‘Please fill in a :attribute.’, ‘…’ => ‘…’ ..

Read more

I am building a user’s resignation inside the dashboard with Form Request Validation. it works well in store resource, but I need to exclude the password role in updating resource, so if the user leaves it empty I will store the old password my validation file namespace AppHttpRequests; use IlluminateFoundationHttpFormRequest; class UsersRequest extends FormRequest { ..

Read more

I am using Laravel Framework 8.62.0 and I am having the following validation rules: $rules=[ ‘username’ => ‘required|min:3|max:30|alpha_dash’, ’email’ => "required|email|unique:users,email", ‘password’ => ‘required|min:6|confirmed’, ]; $error_messages=[ ‘username.required’=>’The username-field is required.’, ‘username.min’=>’Your username must be longer than 3 characters.’, ‘username.max’=>’Please shorten your username.’, ‘username.alpha_dash’=>’Please use letters from A-Z and a-z, dashes (-) or underscores(_).’, ’email.unique’=>’Your email ..

Read more

the value in patternName field is stored in pattern_name column of course_patterns table. When i added unique validation for this field, am getting the error BadMethodCallException: Method IlluminateValidationValidator::validatePatternName does not exist in file C:wamp64wwwLaravelprojectsabcdvendorlaravelframeworksrcIlluminateValidationValidator.php on line 1509. otherwise, evrything works fine. As the soft deleted rows are not counted for unique validation, i added below ..

Read more

$validator = Validator::make($request->all(), [ ’email’ => ‘required|min:9|max:50|email’, ‘password’ => ‘required|min:8|max:255|password’ ]); if ($validator->fails()) { echo "Failed! Sorry :("; Session::flash(‘error’, $validator->messages()->first()); //return Redirect::back()->withErrors($validator); } else {… But if I write ‘password’ => ‘required|min:8|max:255’ the validation is passed, but when I write ‘password’ => ‘required|min:8|max:255|password’ it doesn’t pass and the result is "Failed! Sorry :(". I mean ..

Read more

In my laravel based application, when updating user accounts I’m trying to validate the birthday field. I have the following in my controller’s update method ‘date_of_birth’=>[‘required’,’date’, ‘date_format:Y-m-d’, function ($attribute, $value, $fail) { $age=Carbon::createFromFormat(‘Y-m-d’, $value)->diff(Carbon::now())->y; if($age<18||$age>70){ $fail(‘Âge invalide. l’âge devrait être 18-70’); } },] So the date format has to be Y-m-d and the age range ..

Read more

In my laravel based application, when creating new user accounts I’m trying to validate the birthday field. I have the following in my controller’s store method ‘date_of_birth’=>[‘required’,’date_format:m/d/Y’,function ($attribute, $value, $fail) { $age=Carbon::parse($value)->diff(Carbon::now())->y; if($age<18||$age>70){ $fail(‘Âge invalide. l’âge devrait être 18-70’); } },] So the date format has to be m/d/Y and the age range has to ..

Read more