mikelovelyuk
mikelovelyuk

Reputation: 4152

Unable to Print Raw SQL

I've tried various options. I just want to get the raw sql for this;

$payments = Payment::select('Vendor ZIP')->whereIn('Vendor ZIP', $postcodes)->get()->toArray();

I've tried;

//this
dd(array($payments)); 

//this one
Event::listen('illuminate.query', function($payments)  
    { 
        dd(array($payments));
    });

//this one too
$sql = str_replace(['%', '?'], ['%%', "'%s'"], $payments->toSql());
$fullSql = vsprintf($sql, $payments->getBindings());
print_r($fullSql);

I mostly get a No data received error message on the browser. What else can I try?

The query is 100% correct by the way.

Upvotes: 0

Views: 79

Answers (1)

Noman Ur Rehman
Noman Ur Rehman

Reputation: 6957

You can use the toSql method to get the raw SQL query.

$payments = Payment::select('Vendor ZIP')->whereIn('Vendor ZIP', $postcodes)->toSql();

Upvotes: 1

Related Questions