laravel - 在同一控制器 Laravel 中将变量从一种方法传递到另一种方法
问题描述
我需要从 store 方法中传递 select 选项值来显示我需要传递$typeg值来显示方法
public function store(Request $request ) {
$typeg = $request->input('type');
}
public function show($id) {
dd($this->store($typeg));
}
我得到未定义的变量:
或者
函数 app\Http\Controllers\appController::show() 的参数太少,通过了 1 个,预期正好有 2 个
解决方案
在第一个函数上试试这个,你有一些variable
女巫你想把它传递给另一个函数\方法
比您需要使用$this
的名称和您想传递的其他方法的名称var
也像这样。
public function oneFunction(){
$variable = "this is pretty basic stuff in any language";
$this->anotherFunction($variable)
}
public function anotherFunction($variable){
dd($variable);
}
推荐阅读
- css - 是否有全局样式滚动条的解决方案?
- c# - 如何在 C# 中使用拆分器容器?
- php - 图片名称“+”为什么会抛出404
- react-native - 在 IOS 平台上恢复产品时出错
- docker - pip 在 docker 容器上安装 django-rest-framework-social-oauth2 时出错
- powerbi - 在 PowerBI 中使用计算列和度量时的不同结果
- java - 启动GUI程序时无界面
- java - 使用 Spring Boot 配置 Apache Ignite
- html - “Django”添加好友请求错误(没有用户匹配给定的查询)
- sorting - 如何在 Prolog 中使用此合并排序代码?