这里需要将 Employee ID 传递给其他函数以作为外键存储在其他表中

Here in need to Pass Employee ID to other functions to store as foreign key in other tables

我需要将Employee ID 传递给其他函数作为其他表中的外键。

这是我要传递的 submitEmployeeBasic 函数:

public function submitEmployeeBasic(Request $request)
    {
        $employee = new Employee;
        $employee->employee_code=$request->get('empl_code');
        $employee->employee_file_no=$request->get('empl_file_no');
        $employee->employee_name=$request->get('empl_full_name');
        $employee->employee_grade=$request->get('empl_grade');
        $employee->employee_work_site=$request->get('empl_work_site');

        $employee->employee_notes=$request->get('empl_notes');

        $employee->save();
        $emp_id = $employee->id;
        $this->getEmp($emp_id);
        return redirect(route('emplisiting'));

    }

这是我的 store 函数。我需要将 $emp_id = $employee->id; 传递给此函数。

public function saveEmployeePersonal(Request $request){
        $emp_personal = new EmployeePersonal;

        $emp_personal->employee_father_name=$request->get('empl_father_name');
        $emp_personal->employee_mother_name=$request->get('empl_mother_name');
        $emp_personal->employee_spouse_name=$request->get('empl_spouse_name');
        $emp_personal->employee_gender=$request->get('empl_gender');
        $emp_personal->employee_child=$request->get('empl_child');
        $emp_personal->employee_religion=$request->get('empl_religion');
        dd($emp_personal);
        $emp_personal->save();
        return redirect(route('emplisiting'));
    }

提前致谢。

值可以像下面那样传递给路由

$emp_id = $employee->id;
return redirect()->route('emplisiting')->with(compact('emp_id'));

在重定向的地方可以像$emp_id一样访问该值。