Change to:
public function rules()
{
return [
"studentId" => "required | numeric | unique:students,studentId,".$this->route('id'),
"ssn" => "required | numeric | unique:students,ssn,".$this->route('id'),
"epsbId" => "required | numeric | unique:students,epsbId,".$this->route('id'),
"first" => "required",
"last" => "required",
"gender" => "required",
"ethnicity" => "required",
"email" => "email",
"birthdate" => "date"
];
}
Thanks for the response. I tried this and got the same results. I am at a complete loss on this one.
Any other ideas? Something silly I am missing?
is it because those rules are being applied to the update but are really for when you ADD a new user..
wasnt there a way of differentiating rules between add/update?
you are absolutely right. I don't know if it needs to be a separate Request or there is some other means to dynamically change the rules.
I am also not totally sure I have the unique rules setup correctly above. I have tried many different variations of code to add the id parameter to the unique check, but none of them seem to make any difference.
Seems like there will also need to be checks put in to see if the unique fields change. If they change, then the unique validation will need to be checked again.
oh the headaches.
1> add on the top of CreatestudentRequest (model name)
App/Student
2>in ur rule define this
if( $this->get('_method') ==='PATCH')
{
$user_id=$this->get('user_id');
$id= Student::where( 'user_id' , $user_id )->first()->id;
}
else
$id=' ';
3> change field values into
"studentId" => "required | numeric | unique:students,studentId,".$id,
"ssn" => "required | numeric | unique:students,ssn,".$id,
"epsbId" => "required | numeric | unique:students,epsbId,".$id,
4> if you have any exception for any of youre app just use these var_dump() | var_export() | dd()
to know about the errors
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community