我如何在表单提交的 employee_id 下向用户 table 提交员工 table id(自动递增)
how can i submit the employee table id (auto increment) to the user table under the employee_id on form submit
public function store(Request $request)
{
Employees::create([
'first_name'=>$request['first_name'],
'last_name'=>$request['last_name'],
'email'=>$request['email'],
'contact_no'=>$request['contact_no'],
'join_date'=>$request['join_date'],
'date'=>$request['date'],
'employee_no'=>$request['employee_no'],
'no'=>$request['no'],
'profile'=>$request['profile'],
'dob'=>$request['dob'],
'leave_eligible_date'=>$request['leave_eligible_date'],
'leave_eligible_date'=>$request['leave_eligible_date'],
'employee_type_id'=>$request['employee_type_id'],
'employee_designation_id'=>$request['employee_designation_id'],
'employee_department_id'=>$request['employee_department_id'],
'organization_hierarchy'=>$request['organization_hierarchy'],
'direct_contact_person_id'=>$request['direct_contact_person_id'],
'status'=>$request['status']
]);
我想在表单提交
的 employee_id 列下将员工 table id 发送给用户 table
User::create([
'name'=>$request['first_name'],
'email'=>$request['email'],
'photo'=>$request['profile'],
'employee_id'=>$request['????'], // i want send this line
'password'=>Hash::make($request['password'])
]);
}
上面的代码会将数据插入到两个table中,但我希望将自动递增的员工table id插入到[=下的用户table中19=] 表单提交列。
只需获取Employee Create函数的响应并获取Employee id,然后将其传递给User create函数。
$employee = Employees::create([
'first_name'=>$request['first_name'],
'last_name'=>$request['last_name'],
'email'=>$request['email'],
'contact_no'=>$request['contact_no'],
'join_date'=>$request['join_date'],
'date'=>$request['date'],
'employee_no'=>$request['employee_no'],
'no'=>$request['no'],
'profile'=>$request['profile'],
'dob'=>$request['dob'],
'leave_eligible_date'=>$request['leave_eligible_date'],
'leave_eligible_date'=>$request['leave_eligible_date'],
'employee_type_id'=>$request['employee_type_id'],
'employee_designation_id'=>$request['employee_designation_id'],
'employee_department_id'=>$request['employee_department_id'],
'organization_hierarchy'=>$request['organization_hierarchy'],
'direct_contact_person_id'=>$request['direct_contact_person_id'],
'status'=>$request['status']
]);
$user = User::create([
'name'=>$request['first_name'],
'email'=>$request['email'],
'photo'=>$request['profile'],
'employee_id'=> $employee->id, // here use the column of employee id
'password'=>Hash::make($request['password'])
]);
public function store(Request $request)
{
Employees::create([
'first_name'=>$request['first_name'],
'last_name'=>$request['last_name'],
'email'=>$request['email'],
'contact_no'=>$request['contact_no'],
'join_date'=>$request['join_date'],
'date'=>$request['date'],
'employee_no'=>$request['employee_no'],
'no'=>$request['no'],
'profile'=>$request['profile'],
'dob'=>$request['dob'],
'leave_eligible_date'=>$request['leave_eligible_date'],
'leave_eligible_date'=>$request['leave_eligible_date'],
'employee_type_id'=>$request['employee_type_id'],
'employee_designation_id'=>$request['employee_designation_id'],
'employee_department_id'=>$request['employee_department_id'],
'organization_hierarchy'=>$request['organization_hierarchy'],
'direct_contact_person_id'=>$request['direct_contact_person_id'],
'status'=>$request['status']
]);
我想在表单提交
的 employee_id 列下将员工 table id 发送给用户 table User::create([
'name'=>$request['first_name'],
'email'=>$request['email'],
'photo'=>$request['profile'],
'employee_id'=>$request['????'], // i want send this line
'password'=>Hash::make($request['password'])
]);
}
上面的代码会将数据插入到两个table中,但我希望将自动递增的员工table id插入到[=下的用户table中19=] 表单提交列。
只需获取Employee Create函数的响应并获取Employee id,然后将其传递给User create函数。
$employee = Employees::create([
'first_name'=>$request['first_name'],
'last_name'=>$request['last_name'],
'email'=>$request['email'],
'contact_no'=>$request['contact_no'],
'join_date'=>$request['join_date'],
'date'=>$request['date'],
'employee_no'=>$request['employee_no'],
'no'=>$request['no'],
'profile'=>$request['profile'],
'dob'=>$request['dob'],
'leave_eligible_date'=>$request['leave_eligible_date'],
'leave_eligible_date'=>$request['leave_eligible_date'],
'employee_type_id'=>$request['employee_type_id'],
'employee_designation_id'=>$request['employee_designation_id'],
'employee_department_id'=>$request['employee_department_id'],
'organization_hierarchy'=>$request['organization_hierarchy'],
'direct_contact_person_id'=>$request['direct_contact_person_id'],
'status'=>$request['status']
]);
$user = User::create([
'name'=>$request['first_name'],
'email'=>$request['email'],
'photo'=>$request['profile'],
'employee_id'=> $employee->id, // here use the column of employee id
'password'=>Hash::make($request['password'])
]);