[英]Pass parameter from one function to other function in the same Controller Laravel
I have two functions in the same controller.我在同一个控制器中有两个功能。 How can i pass $id from search($id) function to searchcond() function.如何将 $id 从 search($id) 函数传递给 searchcond() 函数。
My First function:我的第一个功能:
public function search($id)
{
return view('frontend.studentinfoajax', compact('data_dep', 'data_branch_dep'));
}
My Second Function:我的第二个功能:
public function searchcond()
{
return DB::table('studentinfo')
->where('branchID', '=', $id)
->orderby('fullname')
->get();
}
How can i pass $id from search($id) function to searchcond() function.如何将 $id 从 search($id) 函数传递给 searchcond() 函数。
I dont know why you need like that but still if you need you can use class properties我不知道你为什么需要那样,但如果你需要,你可以使用类属性
private $id; //define property to the class
public function search($id)
{
$this->id=$id;
return view('frontend.studentinfoajax',
compact('data_dep',
'data_branch_dep'));
}
public function searchcond()
{
$id=$this->id;
return DB::table('studentinfo')
->where('branchID', '=', $test)
->orderby('fullname')
->get();
}
After seeing the code snippets you have provided what i understood that you want to acheive something like this :在看到代码片段后,您已经提供了我理解的内容,您想要实现这样的目标:
public function search($id)
{
$data = $this->searchcond($id);
return view('frontend.studentinfoajax', compact('data_dep', 'data_branch_dep'));
}
private function searchcond($id)
{
return DB::table('studentinfo')
->where('branchID', '=', $id)
->orderby('fullname')
->get();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.