Php 在雄辩的where子句中使用变量
在雄辩的where子句中使用变量的正确方法是什么 例如,这是我的字符串变量Php 在雄辩的where子句中使用变量,php,eloquent,where,Php,Eloquent,Where,在雄辩的where子句中使用变量的正确方法是什么 例如,这是我的字符串变量 $testVar = 'Dave, Tom, Brad'; 这是我雄辩的问题 $spielerArray = Spieler::join('PlanungSpieler', 'PlanungSpieler.Player_ID', '=', 'Spieler.Player_ID') ->whereIn('Spieler.Name', [$testVar]) ->
$testVar = 'Dave, Tom, Brad';
这是我雄辩的问题
$spielerArray = Spieler::join('PlanungSpieler', 'PlanungSpieler.Player_ID', '=', 'Spieler.Player_ID')
->whereIn('Spieler.Name', [$testVar])
->get();
当我将这个$testVar放入查询时,我得到一个空结果。但这是不对的。因为我有Dave Tom和Brad的值。在您的例子中,
$testVar
是字符串,那么您必须转换为数组
$testVar = 'Dave, Tom, Brad';
$myArray = explode(',', $testVar);
之后,您可以将$myArray
传递到中,其中
$spielerArray = Spieler::join('PlanungSpieler', 'PlanungSpieler.Player_ID', '=', 'Spieler.Player_ID')
->whereIn('Spieler.Name', $myArray )
->get();
可能使用
$myArray=array\u map('trim',$myArray)代码>或使用,