我从员工那里得到了手机号码,我必须在部门函数中传递$mobile变量。那么我如何在另一个请求类型的函数中使用函数的变量呢。
public function employee($id){
$result= Employee::where('emp_id',$id)->get();
$mobile= $result[0]['mobile'];
}
public function department(Request $request){
$req= new Department
$req->name= $request->name;
$req->emp_id=$request->eid;
$req->emp_mobile=$mobile //the variable want to pass
$req->save();
}
在employee函数上,添加此代码
public function employee($id){
$result= Employee::where('emp_id',$id)->get();
$mobile= $result[0]['mobile'];
return $mobile;
}
关于部门职能:
public function department(Request $request){
$req= new Department
$req->name= $request->name;
$req->emp_id=$request->eid;
$req->emp_mobile = $this->employee($request->eid);
$req->save();
}