mysql - 想用两个请求值查找
问题描述
我想用两个请求值更新我的列数据。我尝试了一个值。我不知道在哪里和方法。
Gold::where('type', '=', $request->type)->firstOrFail();
这仅适用于一个请求值查询搜索。但我想用 where query.how 用 laravel find 方法检查传入类型和 parent_id 的两个值。最后,我想更新检查两个值都包含数据并更新它的其他列值,就像这样。
$gold = Gold::where('type', '=', $request->type)->firstOrFail();
$gold->comment = $request->input('comment');
$gold->userid = $request->input('userid');
$gold->save();
解决方案
根据您在问题评论中提供的 SQL 查询,这里是 Laravel 模型的解决方案:-
# this query will find your Gold item with there provided where conditions.
# you can pass more where conditions as per your requirements.
$gold = Gold::where('type', '=', $request->input('type'))
->where('parent_id', '=', $request->input('parent_id'))->first();
if(!$gold) {
return throw Exception('Invalid Gold Item', 422);
}
$gold->comment = $request->input('comment');
$gold->userid = $request->input('userid');
$gold->save();
这是我理解的根据您的要求的解决方案。
推荐阅读
- node.js - 节点升级后 Rails 应用程序无法运行
- pagination - Apollo Client fetchMore 获取基于游标的分页的上一页
- c++ - 为 iOS 构建,但链接库是为 MacOS 构建的
- html - 为什么我的“导航”对齐和背景颜色不起作用?
- r - 获取包含R中值列表的列中的汇总频率
- neo4j - 获取Node4J中每个节点的叶子
- sql-server - Microsoft SSMA 使用 powershell 和安全密码调用 SSMAforAccessConsole32.exe
- java - 泛型类型参数有什么区别?和对象
- bash - 为什么变量BASH_ARGV在函数中的值不同,取决于调用函数前是否使用
- c - 使用指针将 fprintf() 转换为 C 中的 csv 文件