Laravel 5 如何将员工表id(自动递增)提交到表单submit上员工id下的用户表

Laravel 5 如何将员工表id(自动递增)提交到表单submit上员工id下的用户表,laravel-5,laravel-5.6,Laravel 5,Laravel 5.6,我想将Employee表id发送到表单submit上Employee_id列下的用户表 public function store(Request $request) { Employees::create([ 'first_name'=>$request['first_name'], 'last_name'=>$request['last_name'], 'email'=>$request['email'],

我想将Employee表id发送到表单submit上Employee_id列下的用户表

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插入表单submit上employee_id列下的user表中。

只需获取employee Create函数的响应,获取employee id,然后将其传递给user Create函数即可

      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'])
     ]);
}

在Employees::create之后是User::create in the same store函数吗?是的,这两个函数都在同一个函数中,因为使用一个表单将数据插入两个表中
$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'])
 ]);