@azadi ok. what's the problem?
We don't see the question (just some pieces of code), we don't know how you call validator function, we don't know what $message contains. How we can help you?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a form of gender.
<div class="col-md-6">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="gender" id="sir" value="1">
<label class="form-check-label" for="sir">sir</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="gender" id="lady" value="0">
<label class="form-check-label" for="lady">lady</label>
</div>
@error('gender')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
Controller
protected function validator(array $data)
{
return Validator::make($data, [
'gender' => ['required', 'in:0,1'],
]);
}
@azadi ok. what's the problem?
We don't see the question (just some pieces of code), we don't know how you call validator function, we don't know what $message contains. How we can help you?
@SilenceBringer The $message is RegisterController.php
@azadi great. Can I see Register controller?
And THE MOST IMPORTANT question: what's wrong with your code? Any error?
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\State;
use App\Providers\RouteServiceProvider;
use App\Models\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Show the application registration form.
*
* @return \Illuminate\View\View
*/
public function showRegistrationForm()
{
$states = State::all();
return view('auth.register', compact('states'));
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'first_last_name' => ['required', 'string', 'max:255'],
'mobile' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
'national_ode' => ['required', 'number', 'max:12'],
'state_id' => 'required',
'city_id' => 'required',
'address' => 'required',
'gender' => ['required', 'in:0,1'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\Models\User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
}
This code is not error
@azadi So it works? Great! Assume it was just to show off your code then?
@Sinnbeck It is not working. I want to show message validation when I did not check the gender.
@azadi Yes? You never call the validate method anywhere?? And what method are you calling with that form? You dont show the form part, so we have no way of knowing
@Sinnbeck Well, I have sent you the complete code. say where did I stay?
@azadi This isnt a form
<div class="col-md-6">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="gender" id="sir" value="1">
<label class="form-check-label" for="sir">sir</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="gender" id="lady" value="0">
<label class="form-check-label" for="lady">lady</label>
</div>
@error('gender')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
@azadi Ok so the request is sent to {{ route('register') }}? Show that method in the controller. It should be a public method.
protected function validator(array $data)
{
dd($data);
@azadi Can you show the route definition for that? And controller methods you want to use should be public
@Sinnbeck How?
@azadi Nevermind. Make sure you actually hit that validator.
protected function validator(array $data)
{
dd('hit');
return Validator::make($data, [
^ "hit"
@Sinnbeck it's looks like standard LaravelUi code, mostly handled in RegistersUsers trait
@azadi and dd($data) ?
@Snapey Yeah just noticed. Why it took it back :)
^ array:12 [▼
"_token" => "KxaqY0m7mDg9yfCmTyjF1iMIdtKopldf2JV2B3Ud"
"name" => "aa"
"first_last_name" => "aa"
"email" => "[email protected]"
"mobile" => "123"
"password" => "123456789"
"password_confirmation" => "123456789"
"national_ode" => "123"
"gender" => "1"
"state_id" => "8"
"city_id" => "87"
"address" => "www"
]
@azadi So gender is 1 and there should be no validation error?
So what if it was empty? Or what if it is not selected? Or what if it is not even 1 or 0?
@azadi Then you would get a validation error
@azadi have you tried setting the value to something else to see if it errors?
@Sinnbeck I see the validation error for everyone. But I don't see this radio button or I don't see it at all.
@azadi What?
@azadi Yes laravel shows validation errors for all wrong fields? Thats how validation works.. You can set it to stop on first failure if you want. https://laravel.com/docs/9.x/validation#stopping-on-first-validation-failure
@Sinnbeck Like this
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'first_last_name' => ['required', 'string', 'max:255'],
'mobile' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
'national_ode' => ['required', 'number', 'max:12'],
'state_id' => 'required',
'city_id' => 'required',
'address' => 'required',
'gender\.0' => 'required',
'gender\.1' => 'required',
]);
}
@azadi no
@Sinnbeck How?
@azadi You didnt check the link I assume? Or you just scrolled to a different part of the docs? It specifically says bail
'gender' => ['bail', 'required', 'in:0,1'],
Be sure to add it to all validation rules, if you want it to only show the first one that fails for some reason (still have no clue why you would want this)
@Sinnbeck What is bail?
@azadi From the docs i linked
Sometimes you may wish to stop running validation rules on an attribute after the first validation failure. To do so, assign the bail rule to the attribute:
But maybe explain exactly what you want. You only gave a picture and I assumed you meant this.. But I have no way of knowing what you are thinking
@Sinnbeck When a user did not select the radio button, I want to see this
It is mandatory to fill in the gender option
@azadi Ah ok so it just doesnt show that validation message? Did you remember to check the data using dd() to ensure it is empty ??
^ array:10 [▼
"_token" => "KxaqY0m7mDg9yfCmTyjF1iMIdtKopldf2JV2B3Ud"
"name" => null
"first_last_name" => null
"email" => null
"mobile" => null
"password" => null
"password_confirmation" => null
"national_ode" => null
"state_id" => null
"address" => null
]
@azadi That shoudl work. Did you change the validation in any way?
@Sinnbeck no
'gender' => ['bail', 'required', 'in:0,1'],
@azadi Remove the bail again. I just misunderstood what you wanted then. But without it it should work. I cannot spot the error currently
@Sinnbeck I changed
'gender' => ['required', 'in:0,1'],
But I did not see a message of
It is mandatory to fill in the gender option
Well at least after 46 posts we can finally start working on the problem. Let me help you write what should have written in the very first post
I have this code inside a form. There is validation on all fields, and it works. For some reason I cannot get this radio input to fail validation, and show an error message. If I dont check any of the radio buttons, I dont get
genderin the backend validation so I would assume it should show an error message
Can you try adding this, and see if that has the error message?
@foreach ($errors->all() as $key => $error)
<li>{{$key}} {{ $error }}</li>
@endforeach
I see this
The name field is required.
The first last name field is required.
The mobile field is required.
The email field is required.
The password field is required.
The national ode field is required.
The state id field is required.
The city id field is required.
The address field is required.
The gender field is required.
@azadi So it works. Delete this and copy it from this page
@error('gender')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
blade
@error('gender')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
MyController
'gender' => ['required', 'in:0,1'],
But I see did not message
@azadi And you tried deleting it and writing it again (the blade part).
@Sinnbeck Yes, But my problem did not solve yet.
@azadi Can you try this?
@foreach ($errors->all() as $key => $error)
<li>{{$key}} {{ $error }}</li>
@endforeach
The name field is required.
1 The first last name field is required.
2 The mobile field is required.
3 The email field is required.
4 The password field is required.
5 The national ode field is required.
6 The state id field is required.
7 The city id field is required.
8 The address field is required.
9 The gender field is required.
@azadi Should have been
@foreach ($errors->getMessages() as $key => $error)
<li>{{$key}} {{ $error[0] }}</li>
@endforeach
@azadi Typo fixed
Or just do this to see the keys
@foreach ($errors->getMessages() as $key => $error)
<li>{{$key}} </li>
@endforeach
name The name field is required.
first_last_name The first last name field is required.
mobile The mobile field is required.
email The email field is required.
password The password field is required.
national_ode The national ode field is required.
state_id The state id field is required.
city_id The city id field is required.
address The address field is required.
gender The gender field is required.
name
first_last_name
mobile
email
password
national_ode
state_id
city_id
address
gender
@azadi Then I can only say, you are doing something wrong in your code that I cannot see. Maybe try renaming the field to something else? sex perhaps
@Sinnbeck I change to sex, but my problem did not solve yet.
@azadi Ok. No clue what is wrong then.
@Sinnbeck what's the solution?
@azadi Give the code to a senior developer and ask them to fix it.
Or put the code on github, so people can see the whole picture
@Sinnbeck Have you AnyDesk? 193088641
@azadi No
Oxbir, you even have a problem with just plain html, unbelievable...
@MichalOravec Where is the problem in this code?
@azadi you tell us. We can't see any problem, and you are too lazy to describe the problem, then also say ' this code is not problem'
@Snapey No, I am not lazy
@azadi so put some effort into your question. Tell us what the issue is, and what you have done to try and resolve the issue
@MichalOravec Thanks
The only reason I can think that the rules will not be recognised is if you have a non-visible character in the rules array, since you have already proved that the rules array is being checked, and that when no radio is selected, the gender field is missing from the data being validated.
or
The error is being caught but is not displayed - again because of a mismatch in the names between the validation rule and the @error view.
I would delete 'gender' from each place its used (including the quotes) and retype at each place.
You are really idiot Oxbir...
The class invalid-feedback is by default display: none;
https://getbootstrap.com/docs/5.0/forms/validation/#server-side
@MichalOravec holy hell 😩 I hate bootstrap sometimes. Last time..
@Sinnbeck It's easier to ask and annoy people than to read the documentation...
@Sinnbeck Confusing.
invalid-feedback is changed to block visibility when preceded by an element with .is-invalid class.
.is-invalid~.invalid-feedback
{
display: block;
}
Like you say, 20 seconds with the developer tools would have confirmed the issue.
Btw @azadi who is your employer?
Please or to participate in this conversation.