如何根据输入的参数提取一行,然后将数据传递给视图?
我有此代码,但它不起作用:
$taxableBase = $request->taxableBase;
$lowerL_and_upperL = DB::table('table_taxes')->whereBetween($taxableBase, ['lower_limit', 'upper_limit'])->get();
return view('calculator.taxes', compact('lowerL_and_upperL'));
php中的以这种方式可以正常工作:
$lowerL_and_upperL = $conexion->prepare('SELECT * FROM table_taxes WHERE ? BETWEEN lower_limit AND upper_limit');
$lowerL_and_upperL->execute([$taxableBase]);
while ($row = $lowerL_and_upperL->fetch()) {
$lower_limit = $row['lower_limit'];
$upper_limit = $row['upper_limit'];
}
答案 0 :(得分:0)
您没有给出两个变量或限制。您刚刚给了两个字符串数组
$taxableBase = $request->taxableBase;
$lowerL_and_upperL = DB::table('table_taxes')->whereBetween($taxableBase, [$lower_limit, $upper_limit])->get();
return view('calculator.taxes', compact('lowerL_and_upperL'));
答案 1 :(得分:0)
制作where()
子句。
$taxableBase = $request->taxableBase;
$lowerL_and_upperL = DB::table('table_taxes')->where(function($q) use ($taxableBase){
$q->where('lower_limit', '<=', $taxableBase);
$q->where('upper_limit', '>=', $taxableBase);
})->get();
return view('calculator.taxes', compact('lowerL_and_upperL'));
为进一步查询,Here是用SO回答的另一个问题。