'Laravel print last executed SQL query with Query log

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 querylog with bind array and all - How can I get the pure SQL, so I can run it in PhpMyAdmin



Solution 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;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ritesh Khatri