我是 Laravel 的新手。我想使用 laravel 查询生成器进行动态查询。
通常我可以在php中进行动态查询
$where = array(
'hello' => 'world'
);
function get($where = null){
if($where == "") $where = "";
//Function which converts where clause into queries
wheretoqueries($where); //converts where clause
$sql = "SELECT * FROM $tbl $where";
return $sql;
}
echo get($where);
如果 where 子句为空查询将是
SELECT * FROM $tbl
如果 where 子句不是 null 查询将是
SELECT * FROM $tbl WHERE hello = "world"
如果键和值存在,Laravel orm 适用于 where 子句
A::where($where)->get();
如果 where 为 null,则以下方法将不起作用