[英]How to pass array in laravel where condition?
$table='user';
$conditions=array(
'uname' => 'test',
'pwd' => '123'); //uname and pwd are the column names
DB::table($table)->where($conditions)->get();
while excuting above code its showing following error 在执行上面的代码时显示以下错误
ErrorException
strtolower() expects parameter 1 to be string, array given
Can any one help me pls. 谁能帮助我。
I don't know which classes you are using but your php compilator said that you passed array instead of string, so maybe try pass conditions in string format: 我不知道您正在使用哪个类,但是您的php编译器说您通过了数组而不是字符串,所以也许尝试以字符串格式传递条件:
$conditions = "uname='test'&pwd='123'";
UPDATE 更新
As you can see in docs ( http://laravel.com/docs/queries#selects ), you can only pass strings to where
method so you have to do sth like that: 正如您在docs( http://laravel.com/docs/queries#selects )中所看到的那样,您只能将字符串传递给
where
方法,因此您必须这样做:
$select = DB::table($table);
foreach($conditions as $column=>$value){
$select->where($column,'=',$value);
}
$result = $select->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.