How to get the raw SQL query from the Laravel Query Builder in laravel8.0
Solution 1:
If you want to show all the queries, then you will have to enable the query log. DB::enableQueryLog
\DB::enableQueryLog(); // enable the query log before your modal
App\User::query()
->where('created_at', '<', now()->subYear())
->with('assignedApps', 'courses')
->orderBy('email', 'asc')
->limit(5)
->get();
dd(DB::getQueryLog()); // after your query, dump and die get query log.
It will return all queries result with values