How To Print Or Debug Query In Laravel?

Laravel 7 , Laravel , Laravel 6

Nicesnippets

353

10-06-2021


Hi Guys,

In this example,i will learn you how to debug query in laravel.you can eay and simply debug query in laravel.

we need to print the queries which are large in nature. Laravel provides built-in functions to do our job. So let’s see how to print or debug query In Laravel.

Example 1: dd() Method

The dd method will print the query information and then stop executing the request.

/**

* The attributes that are mass assignable.

*

* @var array

*/

public function index()

{

$users = DB::table('users')->where('id', '=', 1)->dd();

}

Example : dump() Method

The dump method is similar like a dd. The dd means die & dump while we are using dump only here.

/**

* The attributes that are mass assignable.

*

* @var array

*/

public function index()

{

$users = DB::table('users')->where('id', '=', 1)->dump();

}

Example : tosql() Method

/**

* The attributes that are mass assignable.

*

* @var array

*/

public function index()

{

$users = DB::table('users')->where('id', '=',1)->toSql();

}

Output:


It will help you..


Recommended Posts