0
DB::enableQueryLog();
$mines = Cranks::where([['crank_id', '=', $this->crank_id], ['mine_id', 'like', '%'.$script_value->mine_id.'%'] ])->get();
$querylog =  DB::getQueryLog();
dd($querylog);
exit;

This code prints the query log with bind array and all - How can I get the pure SQL, so I can run it in PhpMyAdmin

2
  • I would install the debug bar. It lists all queries made by a request. Commented Feb 28, 2019 at 13:14
  • As far as I know, you can't. The best I've found is to turn on logging with SET GLOBAL general_log = 1 in the database, run the query, turn logging back off (set to 0), then check the general log to see the exact query that was run. Commented Feb 28, 2019 at 13:31

1 Answer 1

1

using toSql() function you can print your query, like

$mines = Cranks::where([['crank_id', '=', $this->crank_id], ['mine_id', 'like', '%'.$script_value->mine_id.'%'] ])->toSql();
echo $mines;
Sign up to request clarification or add additional context in comments.

3 Comments

This doesn't show the values is in query - I cannot run in PhpMyAdmin by copy pasting the output of this
yeah it doesn't show the dynamic values in query but you can separately echo the values and make you query, or you can go through laarvel debugger tool which provide you exact query. anyways sorry.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.