getherbert / herbert

The WordPress Plugin Framework:
http://getherbert.com/
632 stars 94 forks source link

how to print query ? #130

Closed imajim closed 8 years ago

imajim commented 8 years ago

hello,

How to print the current query in controller ?

I have multiple conditions and i must debug it.

thx to help me ^^

sajadghawami commented 8 years ago

Print into the controller? What do you mean? Do you wanna know how the query looks like?

if so, try


echo $theQuery
imajim commented 8 years ago

in fact, i would like print the sql :

"select ..... Where ...and ...or ... and...."

var_dump($query) print a "Illuminate\Database\Eloquent\Builder"

sajadghawami commented 8 years ago

oke, more code please!

how does your controller, or that part look like?

giwrgos88 commented 8 years ago

@imajim if i have understood right this is what your are looking for

$results = User::where(function($q) use ($request) {
    $q->orWhere('email', 'like', '%john@example.org%');
    $q->orWhere('first_name', 'like', '%John%');
    $q->orWhere('last_name', 'like', '%Doe%');
})->toSql();
dd($results)

instead of the get() or first() use toSql()

please see this for more information link

imajim commented 8 years ago

ahh yes ! it's working. Thanks ^^

jeremyzahner commented 8 years ago

@giwrgos88 Thanks!

giwrgos88 commented 8 years ago

anytime!!