想要找到两个请求值

时间:2019-06-22 14:37:52

标签: mysql laravel

我想用两个请求值更新列数据。我尝试了一个值。我不知道在哪里和方法。

Gold::where('type', '=', $request->type)->firstOrFail();

这仅用于一个请求值查询搜索。但是我想检查两个值传入类型和parent_id与哪里query。如何使用laravel find方法做到这一点。最后,我想更新检查两个值都包含数据并更新它的其他列值。

$gold = Gold::where('type', '=', $request->type)->firstOrFail();
$gold->comment = $request->input('comment');
$gold->userid = $request->input('userid');
$gold->save();

1 个答案:

答案 0 :(得分:0)

根据您在问题注释中提供的SQL查询,这是Laravel Model的解决方案:-

# 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();

这是您所理解的解决方案。