0

I'm using select method of laravel QB and I want to get MYSql command of that's created.

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.

4
  • $result is not a query builder object. post the whole code. Commented Apr 7, 2014 at 7:29
  • @itachi that's not my problem Commented Apr 7, 2014 at 8:57
  • that actually is your problem because toSql() is a method attributed to QueryBuilder object only.... none the less, with this rude attitude, good luck getting an answer from others too. Commented Apr 7, 2014 at 9:27
  • I don't see toSql(). Commented Apr 7, 2014 at 9:44

1 Answer 1

2

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.

$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().

/**
 * Get the SQL representation of the query.
 *
 * @return string
 */
public function toSql()
{
    return $this->grammar->compileSelect($this);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.