Questions tagged [laravel-validation]

This tag references different approaches to validate your application's incoming data using Laravel.

laravel-validation
Filter by
Sorted by
Tagged with
0 votes
1 answer
399 views

Require a field if the value exists in another field, which is an array

Say a model has a status property, that holds an array of strings. If this array contains a string name "Other", the status_other field should be required. I can achieve this with the ...
DarkLeafyGreen's user avatar
0 votes
2 answers
1k views

changing attribute value on validation class in laravel

How can we change attribute values on validation classes in laravel ? consider this code: class Twice implements Rule { public function passes($attribute, $value) { $value = $value * 2; ...
mahdi ghasemi's user avatar
0 votes
2 answers
364 views

Laravel Validator fails everytime even i has posted data

I am new to laravel and trying to use Validator class. It fails everytime though form post the data. i have googled and digged a lot to get answer from internet but none of them worked for me. Please ...
peter anderson's user avatar
-1 votes
1 answer
278 views

How to return a response if the regex validation fails in laravel?

I am developing one API which is responsible for registering the users and the data should store in database upto this part it's working fine, i want to add regex patterns for validation part ,for ...
Sravani's user avatar
  • 407
4 votes
1 answer
5k views

Validating Password rules with a custom error message

Using standard notation like "password.required" I can customize an error message for built-in validation rules. But how can I customize error messages for Illuminate\Validation\Rules\...
IProfessor Man's user avatar
2 votes
1 answer
72 views

Customizing Laravel validation JSON message format - Laravel

I'm trying to figure out how to customize the Form requests to validate By default Laravel gives a good enough JSON format for validation errors but what if we want to customize it? { "...
Marty's user avatar
  • 312
1 vote
1 answer
929 views

Why validation message is shown below of select input with select2 class?

In Laravel 8 / "jquery": "^3.4 / bootstrap 4.6 app I use proengsoft/laravel-jsvalidation library for validation on client side and it works ok, but I have a problems when validation ...
mstdmstd's user avatar
  • 2,753
0 votes
1 answer
2k views

Laravel Call to a member function validate() on null

I'm getting this error on Laravel Auth register Call to a member function validate() on null The error only happens when the validation passes, when it fails it shows returns to the register view ...
Randa Shehada's user avatar
1 vote
2 answers
503 views

Unablen to change Laravel Fortify CreateNewUser Validation

I just installed fortify in a new project am working and would like to change the validation rules. Changing the is not actually the problem, the problem is after i have changed the validation errors, ...
Mandate's user avatar
  • 23
0 votes
0 answers
2k views

Laravel validation requiredIf with array index

I need to apply a required rule to a array field in my form request when the another array field, in the same index, has a certain value. Example: public function rules(): array { return [ '...
guizo's user avatar
  • 2,774
0 votes
1 answer
369 views

Select field validation

<div class="form-group"> <label for="category-id">Category</label> <select id="category-id" class="form-control {{$errors->get('...
Md Nurul Afsar Pervez's user avatar
4 votes
2 answers
1k views

Custom validation not calling the passes() function

I am trying to make a validation that will check whether at least one item is provided in an array following the steps in Custom Validation Rules Routes.php Route::middleware(['auth:api', 'bindings'])...
Owen Kelvin's user avatar
  • 14.6k
0 votes
1 answer
223 views

Laravel-7 pdf validation rule not working

I am trying to validate laravel 7 form validation. But "mimes:pdf" is not even passing the pdf files. Here is my complete code. Even if I choose pdf files and submit the form the validation ...
sanjay kumar behera's user avatar
0 votes
2 answers
1k views

Input Arrays should contain at least one value in Laravel Validation

there I'm facing an issue with the validation, Input arrays should include at least one value for example when I submit a form I get the following inputs array:26 [ "_token" => "...
Zeeshan Haider's user avatar
0 votes
3 answers
5k views

Laravel unique validation, only if value is different & without id

I am trying to update the data and to do this I am using a method patch on my form. Update Validation Request use Illuminate\Validation\Rule; 'question' => [ 'required', 'string', Rule:...
Hardik Sisodia's user avatar
0 votes
3 answers
788 views

How can I enforce the uniqueness of a record in Laravel's database based on another column?

I have a Laravel 8.x application with a database table that includes columns: blockID (primary key), blockName, createdBy, and delete (boolean). When a user adds a new block and submits the form, I ...
user avatar
1 vote
1 answer
203 views

Laravel date_format validation failing for HTML input type week

I got this data from request: { "type": "custom", "start_week": "2020-W19" } And my validation rules are: return [ 'type' => 'required|...
Adem Tepe's user avatar
0 votes
1 answer
4k views

How to format dates in Laravel Excel?

I want to ask, how can we validate dates from Excel file. I have encountered some weird test cases below. Firstly, I have inputted 5/13/2021 in my excel file, but when I dump in, it doesn't display ...
schutte's user avatar
  • 2,139
0 votes
1 answer
56 views

How to validate array by themselves? (laravel)

I have an array of data for example in which they have the same id. [ { id: 222, name: 'Fff', } { id: 223, name: 'Ssss', }, { id: 222, ...
tempra's user avatar
  • 2,745
0 votes
0 answers
916 views

laravel image validation always fail

I have problem to validate my image. Its ok on another project but in new project Laravel 8 always fail. View: <label class="btn btn-primary" for="img" style="margin-top: ...
majid behzadnasab's user avatar
0 votes
2 answers
269 views

Laravel Custom Validation for Table

table 'angkatan' I have table named 'angkatan' which has id, id_angkatan, nama_angkatan, and status. status column is enum contain 'aktif' and 'tidak aktif'. I want to give rules for this table in ...
Mikkel Nurfalah's user avatar
0 votes
2 answers
1k views

laravel Rule::exists by connection and column

I am using the Laravel Excel package to import data from an Excel spreadsheet file. During the importing, I need to verify that some column values exist in an external database table at a specific ...
Pathros's user avatar
  • 10.4k
0 votes
2 answers
618 views

Laravel validator required specific word

I need to validate a string must contains a specific word in the controller. Something Like this ("%name%" is necessary): $request->validate([ 'pattern' => ['required', '...
Morteza Rahmani's user avatar
0 votes
1 answer
476 views

Laravel Blade Display Error Message with Asterisk and Variable Index

I have a form with dynamically generated fields. I validated them. I want to display the error messages. protected $rules = [ 'orderLines.*.item_id' => 'required|exists:items,id' ] ...
Lucid Polygon's user avatar
0 votes
2 answers
4k views

how to avoid duplicate entry in Laravel

I want to give marks for each student for multiple subjects in different grades (10th,11th,12th) now i pick each student id and I can store marks for each student but i want to avoid duplicate entry ...
Atal's user avatar
  • 23
0 votes
1 answer
4k views

Validation in Laravel 8

I´m trying to create a personalized request in Laravel 8. class SendContactFormRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @...
scorpions78's user avatar
0 votes
0 answers
502 views

Laravel why does post request return status 302 instead of 422 when testing missing fields

I am trying to test validation on a Laravel page public function user_can_create_event_page() { $user = User::factory()->create(); $event = Event::factory()->make()->...
Owen Kelvin's user avatar
  • 14.6k
1 vote
0 answers
1k views

Laravel custom Validation Rule on multiple fields and dealing with business logic

I'm working on an endpoint that has data that is very dependant on each other to determine if it is valid. The data coming in will look something like this: { job: 123 activity: 345 date: ...
CJ Brassington's user avatar
0 votes
1 answer
446 views

Any extra field present in request body in laravel API

Suppose my API required following json in request { "name":"User Name", "email":"[email protected]" } But user sending following json in request: { &...
Rohit K's user avatar
  • 11
2 votes
1 answer
2k views

Laravel Form Request Validation rule "required" not working with null values

I have Laravel/Vue application and I'm submiting form with file and some other data using axios. this.loading = true; this.errors = {}; let formData = new FormData(); formData.append('type', ...
sidnas's user avatar
  • 585
2 votes
0 answers
217 views

Laravel 7.4 - Outside of regular expressions, is there any way to validate the parameters of the URL string in a GET request?

I have a URL of the following form: GET /cat/{cat}/meows/{overTime} I can write a controller method that looks like this in order to capture the values: public function getMeowsOverTime(Cat cat, int ...
pickle's user avatar
  • 965
0 votes
2 answers
68 views

Laravel 5.7 validation works still not

I have already asked question about Laravel 5.7 validation, however it still does not work quite right. the validation is not executed at all when sending the content. public function store(Request $...
blackplan's user avatar
  • 256
0 votes
2 answers
180 views

Laravel 5.7 validation makes nothing

My function works by itself but the validation is not executed. Does anyone know what I forgot to add? This is a snippet of my code: namespace App\Http\Controllers; use App\Player; use App\Tournament;...
blackplan's user avatar
  • 256
1 vote
1 answer
706 views

Laravel validation: exclude size check when field not required

I have validation in Laravel application, but I can't seem to make it work. I am making validation on Supplier model not request. public function requestOpening(Supplier $supplier) { $validator = ...
NoOorZ24's user avatar
  • 3,104
2 votes
2 answers
12k views

How to Validate an array in Laravel

I am trying to apply the suggestions provided in this question How to validate array in Laravel? So my validation is 'topics' => 'required|array' Topics are required This works well especially if ...
Owen Kelvin's user avatar
  • 14.6k
1 vote
1 answer
1k views

FormRequest message in laravel 8 not show messages

In my laravel 8 app I am trying to create two files CreateUserRequest and updateUserRequest to use personalized validations. In the method rules I´m calling my model's variable $createRules but when I ...
scorpions78's user avatar
1 vote
0 answers
100 views

Laravel mimes validation rule not working for Microsoft Word Documents

I'm trying to upload .docx file: enter image description here My validation rules: return [ 'first_name' => ['required', 'latin_nameable', 'min:2', 'max:20'], 'last_name' => ...
user3378408's user avatar
1 vote
1 answer
337 views

Laravel Validator requires what is not required

I have some problems with Laravel Validator. I'm sending some images as an array, and it's validating images even if they are empty, but they are not required, it always says that The images must be ...
Rade Ilijev's user avatar
0 votes
2 answers
2k views

Validate json object key in laravel request file

I have below type of json in my laravel request, I want to validate json object key in my laravel request file. I want to validate title value is required of data json. I found solution but it's for ...
User PHP's user avatar
0 votes
1 answer
404 views

Laravel 8 Validation "required" not consistent with documentation

I've been stuck checking all the related rules for an hour: Here is my validation rule request: class CreateRewardRequest extends FormRequest { /** * Determine if the user is authorized to ...
user3803848's user avatar
0 votes
1 answer
332 views

Validating non-required associative array with required fields

I want to validate that if my request contains a field of associative array type, that array needs to contain specific fields (but only if it's present) Ie, array, if present, needs to contain foo: { ...
eithed's user avatar
  • 4,084
2 votes
0 answers
100 views

Replace messages array from the validation MessageBag

I have a class that extends FormRequest class in which I want to replace the entire message array with a new message array This is my method in which successfully fetch old messages but now want to ...
Jatin Kaklotar's user avatar
0 votes
1 answer
946 views

Laravel skipping "required" file validation

i'm having a problem with laravel 8, i really don't know what i'm doing wrong but the files are skipping the required rule in the validation, i'm sending the form with an array of names and files, and ...
elgranchuchu's user avatar
4 votes
3 answers
5k views

Extending/Overriding Laravel Validator Class

In Laravel 8.3, they introduced a new feature, stopOnFirstFailure which stops the validation entirely once a rule fails. I would want to use this feature in Laravel 7. Upon checking the vendor/laravel/...
cjdy13's user avatar
  • 59
1 vote
2 answers
887 views

How to add validation for field accept number and null? [Laravel 7.x]

I want to store the score value as a number when is_pass is true. If is_pass is false then score should be null. So I added validation like below for score 'score' => 'required_if:is_pass,true|...
Senthurkumaran's user avatar
1 vote
1 answer
890 views

Laravel request validation in shallow nested resource

I have two resources Organizations OrganizationUsers Given that I want to create in both resources and that the creation must follow specific requirements, I'm using Request rules() and attributes()...
Tiago Martins Peres's user avatar
2 votes
2 answers
3k views

Avoid html tags in laravel string validation

I want to prevent users of using html tags in their username fields when they are registering, how can I do that? For instance currently I have a user he registered with such username E7JfyqxE4lsbqQ &...
mafortis's user avatar
  • 6,921
0 votes
2 answers
560 views

how to exit when I return laravel Validation?

i' new to laravel here I have created a registration API and private function for validation but not show validation. that is my validation function `private function validateInfo($request, $...
nq tech's user avatar
-1 votes
2 answers
649 views

How to bail when required_unless is passed in Laravel validation

I have a form with these 3 inputs: a text input named "room1" a checkbox like: "☑ I don't need room 2" and named "oneroom" a text input named "room2" By ...
manchitro's user avatar
  • 131
1 vote
2 answers
330 views

I have a problem with laravel validation logic when im trying to update my data

Hello guys im beginner in laravel and i need some help.I have a problem with my validation.When i store data in my bootstrap modal everyting is fine but when i press edit button and want to update, ...
Aleks12's user avatar
  • 23

1 2 3
4
5
18