loading...

Print Last Query In Laravel Eloquent – Examples

pakainfocom profile image pakainfo ・1 min read

In this Debugging example we can get directly get current sql query using toSql() of MySQL Database query builder. In this Debugging example you don’t require to enable query log or something you can directly query like bellow example: last query in laravel

$employee = Employee::where('id',5)->toSql();
dd($employee);

Debugging Example 2 : Dd Last Query Laravel

DB::enableQueryLog();
$employee = Employee::get();
$query = DB::getQueryLog();
dd($query);

Example : Debugging Queries In Laravel

public function lastQuery()
    {
        \DB::enableQueryLog();
        $list = \DB::table("employees")->get();
        $query = \DB::getQueryLog();
        dd(end($query));
    }

5+ ways to get a last query in laravel

Discussion

pic
Editor guide
 

Dude, instead of spamming the platform, maybe proof-read your content first at least?