[英]Laravel get result toSql in QueryBuilder
I'm using select
method of laravel QB and I want to get MYSql
command of that's created. 我正在使用laravel QB的
select
方法,我想获得创建的MYSql
命令。
Laravel QB: Laravel QB:
public function scopeiOS( $query ){
$result = $query->select( DB::raw('count(`platform`) as iOS' ) ) ->where( 'platform' , '=', 'iOS' ) ->pluck('iOS');
}
toSql()
is not member of that function. toSql()
不是该函数的成员。
I don't know about toSql()
but if you want to get the query created then you might want to look at the logs of the queries executed for that request. 我不知道
toSql()
但是如果你想获得创建的查询,那么你可能想查看为该请求执行的查询的日志。
$queries = DB::getQueryLog();
dd($queries);
Or get the last query executed: 或者执行最后一个查询:
$queries = DB::getQueryLog();
$last_query = end($queries);
Or maybe (warning untested code) 或许(警告未经测试的代码)
public function scopeiOS( Illuminate\Database\Query\Builder $query ){
$result = $query->select( DB::raw('count(`platform`) as iOS' ) )
->where( 'platform' , '=', 'iOS' )
->pluck('iOS');
}
Check this for more information on toSql()
. 有关
toSql()
更多信息,请查看此内容 。
/**
* Get the SQL representation of the query.
*
* @return string
*/
public function toSql()
{
return $this->grammar->compileSelect($this);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.