laravel的ORM转为原生sql
注:mysql测试成功,mongoDB测试失败
//将laravel的ORM转为原生sql $SubProfits为laravel的ORM对象
$SubProfits = model::where('id','<=',20)->where('display',1);
$bindings = $SubProfits->getBindings(); //获取参数,本例中为20和1
$sql = str_replace('?', '%s', $SubProfits->toSql());
$sql = sprintf($sql, ...$bindings); //... 为将数组循环转为字符串
...测试
$a = ['a',b];
print_r(...$a);//只输出a;
var_dump(...$a);//输出a,b
纵然世间炎凉百态!我自依旧初心不改!!