简体   繁体   English

将参数从一个函数传递到同一控制器 Laravel 中的另一个函数

[英]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.

相关问题 在laravel控制器中如何将变量从一个函数传递到另一函数 - in laravel controller how to pass variable from one function to other function Laravel:如何在同一控制器中将变量从一个函数传递给来自Ajax调用的另一个函数 - Laravel : how to pass variable from one function to other coming from ajax call in same controller 如何在同一控制器laravel中将参数从一个函数获取到另一个函数 - How to get parameter from one function to another function in the same controller laravel 如何将一些数据从一个函数传递到同一控制器中的另一个函数? -Laravel - How to pass some data from one function to another in same controller ? -Laravel 将变量从一个函数传递到同一控制器中的另一个函数(laravel 5) - Passing variable from one function to another function in same controller (laravel 5) 我想在同一控制器的不同函数中传递变量-Laravel - I want to pass variable in different function from same controller - Laravel 如何在 Laravel 应用程序中从同一 controller 调用其他 function? - How to call other function from the same controller in Laravel application? Laravel将变量从控制器中的1个函数传递给另一个函数 - Laravel pass variable from 1 function in controller to another one Laravel Controller-在函数之间传递变量 - Laravel Controller - Pass a variable from function to function 将变量从一个函数传递到同一控制器中的另一个函数 - Pass variables from one function to another in the same Controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM