将变量从一种方法传递到同一控制器Laravel中的另一种方法 [英] Pass variable from one method to another in same controller Laravel

查看:50
本文介绍了将变量从一种方法传递到同一控制器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);
}

这篇关于将变量从一种方法传递到同一控制器Laravel中的另一种方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆