【发布时间】:2018-02-17 20:08:07
【问题描述】:
我正在为数据库创建查询:
$test_2_lowest = TestsCorrect
::join('results', 'tests_correct.id', '=', 'results.test_result_id')
->where([
['results.user_id', '=', $user_id],
['results.test_id', '=', '2'], // <----
])->min('correct');
这里唯一可变的数字是'2'。 我想以某种方式将其作为变量传递,我不必声明多个变量即可从不同的测试中获得分数。
我尝试了输入名称为数字的表单:
<form action="{{route('results')}}" method="post">
<input type="hidden" name="test_id" value="3"/>
<button type="submit">Send</button></form>
和功能
public function results(Request $test_id)
{
$test_2_lowest = TestsCorrect
::join('results', 'tests_correct.id', '=', 'results.test_result_id')
->where([
['results.user_id', '=', $user_id],
['results.test_id', '=', $test_id->input('test_id');],
])->min('correct');
}
但它不起作用:(
【问题讨论】:
-
从数组中删除
;,这是一个语法错误。另请阅读minimal reproducible example 并解释您的“不起作用”。 -
那个;实际上并没有在代码中,我把它粘贴在这里不好,“不起作用”的意思是“MethodNotAllowedHttpException”,原因是我有 method="post",应该是 method="put"