Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9193895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:16:26+00:00 2026-06-17T21:16:26+00:00

How can I retrieve the raw executed SQL query in Laravel 3/4 using Laravel

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:16:27+00:00Added an answer on June 17, 2026 at 9:16 pm

    Laravel 4+

    Note for Laravel 5 users: You’ll need to call DB::enableQueryLog() before executing the query. Either just above the line that runs the query or inside a middleware.

    In Laravel 4 and later, you have to call DB::getQueryLog() to get all ran queries.

    $queries = DB::getQueryLog();
    $last_query = end($queries);
    

    Or you can download a profiler package. I’d recommend barryvdh/laravel-debugbar, which is pretty neat. You can read for instructions on how to install in their repository.


    Laravel 3

    In Laravel 3, you can get the last executed query from an Eloquent model calling the static method last_query on the DB class.

    DB::last_query();
    

    This, however, requires that you enable the profiler option in application/config/database.php. Alternatively you could, as @dualed mentioned, enable the profiler option, in application/config/application.php or call DB::profile() to get all queries ran in the current request and their execution time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know I can retrieve some settings.xml parameters using properties, like, for example ${settings.localRepository}
How can I retrieve distinct rows from a table using massive ORM . I
I've created a cookie like below and can retrieve all font_size , back_color and
I developp a Java application using Windows Desktop Search from which I can retrieve
How can I retrieve raw time-series data from a Proficy Historian/iHistorian? Ideally, I would
While parsing an XML, given a Node object, can I retrieve the raw XML
It seems like I might be overlooking something obvious, but I can't figure out
I would like to retrieve multiple log files from an Ubuntu server (using Python
I know I can retrieve every parameter in Sinatra using params. However, How can
I can retrieve the contents of a webpage into a variable like: x =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.