0

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.

mikelovelyuk
  • 4,042
  • 9
  • 49
  • 95
  • You have to call `toSql()` before `get()`. See [this question](http://stackoverflow.com/questions/18236294) and [answer](http://stackoverflow.com/a/20382987/170403). – Furgas May 07 '15 at 11:14

1 Answers1

1

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

$payments = Payment::select('Vendor ZIP')->whereIn('Vendor ZIP', $postcodes)->toSql();
Noman Ur Rehman
  • 6,707
  • 3
  • 24
  • 39