Laravel: log all database queries

A code snippet to log all database queries to a separate log file.

Add the following to the boot function of AppServiceProvider.

\DB::listen(function ($query) {
	\File::append(
		storage_path('/logs/query.log'),
		'[' . date('Y-m-d H:i:s') . ']' . PHP_EOL . $query->sql . ' [' . implode(', ', $query->bindings) . ']' . PHP_EOL . PHP_EOL
	);
});