Skip to content

Instantly share code, notes, and snippets.

@imzhi
Created January 15, 2021 02:21
Show Gist options
  • Save imzhi/33897c751168268f7b22e0d8a9056f6f to your computer and use it in GitHub Desktop.
Save imzhi/33897c751168268f7b22e0d8a9056f6f to your computer and use it in GitHub Desktop.
laravel 打印当前 SQL 语句
<?php
$list = Application::with('_user', '_category')
->where(function ($query) {
$query->whereHas('_currentRepostory', function ($hasQuery) {
$hasQuery->where(function ($subQuery) {
$subQuery
->orWhere('name', 'like', '%换声%')
->orWhere('name', 'like', '%换脸%')
->orWhere('name', 'like', '%换头%')
->orWhere('name', 'like', '%假脸%')
->orWhere('name', 'like', '%模拟脸%')
->orWhere('name', 'like', '%声音模拟%')
->orWhere('name', 'like', '%模拟声%')
->orWhere('name', 'like', '%假声%')
->orWhere('name', 'like', '%语音处理%')
->orWhere('name', 'like', '%声音伪造%')
->orWhere('name', 'like', '%肤色%')
->orWhere('name', 'like', '%发型%')
->orWhere('name', 'like', '%虚拟人%')
->orWhere('name', 'like', '%模拟人%')
->orWhere('name', 'like', '%虚拟角色%')
->orWhere('name', 'like', '%模拟角色%')
->orWhere('name', 'like', '%虚拟女%')
->orWhere('name', 'like', '%模拟女%')
->orWhere('name', 'like', '%虚拟男%')
->orWhere('name', 'like', '%模拟男%');
});
});
})
// ->get(['id']);
;
$sqlStr = $list->toSql();
$bindins = $list->getBindings();
foreach ($bindins as $replace) {
$value = is_numeric($replace) ? $replace : "'" . $replace . "'";
$sqlStr = preg_replace('/\?/', $value, $sqlStr, 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment