Level 104
Are you sure you are passing a valid id; how have you modified the AJAX call, and the designationAjax action?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Are you sure you are passing a valid id; how have you modified the AJAX call, and the designationAjax action?
modified code
$this->validate($request,[
'emp_fname'=>'unique:employees|required',
'designation_id' => 'exists:designations,designation_id' // checks if the is a record matching the provided value
]);
controller
public function designationAjax($department)
{
$designation = Designation::where("department_id",$department)
->pluck('designations.designation_name','designations.designation_id')->all();
return json_encode($designation);
}
script
function getDesignation(department) {
if(department) {
$.ajax({
url: '{{url('/')}}/designation/ajax/'+department,
type: "GET",
dataType: "json",
success:function(data) {
console.log(data);
$('select[name="designation_id"]').empty();
$('select[name="designation_id"]').prepend('<option value="">--Select designation--</option>');
$.each(data, function(key, value) {
$('select[name="designation_id"]').append('<option value="'+ key +'">'+ value +'</option>');
});
}
});
} else{
$('select[name="designation_id"]').empty();
}
}
Interesting. So, you are getting the value 2 for designation_id in the request>
when i selected for 2nd option for department_id =2 its gets designation_id=0
using department_id=2 whenever i seleted any option still it getting designation_id=0
@tykus please help !!
Please or to participate in this conversation.