Get the Query Executed in Laravel 3/4

2020-01-24 10:30发布

How can I retrieve the raw executed SQL query in Laravel 3/4 using Laravel Query Builder or Eloquent ORM?

For example, something like this:

DB::table('users')->where_status(1)->get();

Or:

(posts (id, user_id, ...))

User::find(1)->posts->get();

Otherwise, at the very least how can I save all queries executed to laravel.log?

20条回答
爷的心禁止访问
2楼-- · 2020-01-24 10:54

For Laraver 4 it's

DB::getQueryLog()
查看更多
Viruses.
3楼-- · 2020-01-24 10:54

If you are using Laravel 5 you need to insert this before query or on middleware :

\DB::enableQueryLog();
查看更多
登录 后发表回答