[英]Passing variable from one function to another function in same controller
I need to pass a id from a fuction to other function, i tried this way but i cant get the result.我需要将一个函数的 id 传递给其他函数,我试过这种方式,但我无法得到结果。 Can anyone spot the mistake and give me a solution.
任何人都可以发现错误并给我一个解决方案。 This is the exact code i am using
这是我正在使用的确切代码
public function splstaff($id)
{
$staff = DB::select("SELECT staff_id FROM special_labs WHERE sno={$id}");
$this->splstafflist($staff);
}
public function splstafflist($staff)
{
$data=DB::connection('mysql3')->select("SELECT MD5(CONCAT(a.staff_id,a.dob,a.cat_id)) staffid,a.staff_id,a.dep_id,
LOWER(CONCAT(a.legend,' ',a.staff_name))staff_name,a.photo,b.desi_name,IFNULL(c.degree,'')degree,b.desi_orderno,
IFNULL(MIN(sp.date_promotion),a.doj) doj FROM staff_personal_copy a LEFT JOIN staff_designationmaster b ON a.desi_id=b.desi_id
LEFT JOIN staff_qualification_view c ON c.staff_id=a.staff_id LEFT JOIN (camps.staff_promotion sp INNER JOIN staff_designationmaster sd
ON sp.to_designation=sd.desi_id AND sp.status>0 INNER JOIN staff_desigmaster sd1 ON sp.from_design=sd1.desi_id AND
sd1.desi_orderno!=sd.desi_orderno ) ON sp.staff_id=a.staff_id AND b.desi_orderno=sd.desi_orderno WHERE a.staff_id IN ('{$staff}')
AND a.status=1 AND a.cat_id=1 GROUP BY a.staff_id,sd.desi_orderno ORDER BY b.desi_orderno,doj,a.staff_id");
return view('research.labs.staff',['splfac'=>$data]);
}
Uptade the first function adding return
intruction like this:更新第一个添加
return
指令的函数,如下所示:
public function splstaff($id)
{
$staff = DB::select("SELECT staff_id FROM special_labs WHERE sno={$id}");
return $this->splstafflist($staff);
}
I think you might write your fist line of code with less complicated way ...我认为你可以用不太复杂的方式编写你的第一行代码......
$value = DB::table('special_labs')->where('sno',$id)->pluck('staff_id')->first();
return $this->splstafflist($value);
the problem was in this line:问题出在这一行:
$staff = DB::select("SELECT staff_id FROM special_labs WHERE sno={$id}");
you did not use get() method so the result will be a query builder, and when you got the result it will be an array even if it has only one result ... so I recommend using pluck to take only the column you want and first to get the value from the array result ..你没有使用 get() 方法,所以结果将是一个查询构建器,当你得到结果时,它会是一个数组,即使它只有一个结果......所以我建议使用 pluck 只获取你想要的列并首先从数组结果中获取值..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.