将变量从一种方法传递到同一控制器Laravel中的另一种方法
问题描述:
我需要从存储方法中传递选择选项值以显示我需要传递 $ typeg 值以显示方法
I need to pass select option value from store method to show i need to pass the $typeg value to show method
public function store(Request $request ) {
$typeg = $request->input('type');
}
public function show($id) {
dd($this->store($typeg));
}
我明白了未定义的变量:
i get Undefined variable:
或
函数app \ Http \ Controllers \ appController :: show()的参数太少,传递了1个参数,而恰好是2个参数
Too few arguments to function app\Http\Controllers\appController::show(), 1 passed and exactly 2 expected
答
尝试一下在第一个函数上,您有一些 variable
巫婆,您想将其传递给另一个函数\方法
Try this
on the first function you have some variable
witch you want to pass it to another function\method
除了您需要使用 $ this
以及您想通过 var
传递的其他方法的名称之外,还需要使用类似的方法.
Than you need to use $this
and the name of the other method you'd like to pass the var
too something like this.
public function oneFunction(){
$variable = "this is pretty basic stuff in any language";
$this->anotherFunction($variable)
}
public function anotherFunction($variable){
dd($variable);
}