DEV Community

StuartCreed
StuartCreed

Posted on • Updated on

Useful debugging tools

For JS
At work we use a debugging messages which only appear in the dev ENV, defined in your .env file. At some point I will update this post to say how this is done. It is invoked like this:

lsdebug:

lsError({lsModule: this, message: ‘No .added element in the found the root tags element’, data: {cake: 'asd'}})

Outputs the data as an array rather than concatenating like you do in console.log()

console.log('comment', data)

For PHP/Laravel
Telescope Laravel Plugin
var_dump() -> dumps the PHP out to the top of your browser
dd()
ddd()

To view the eloquent commands as sql
DB::enableQueryLog();
DB::getQueryLog();
E.g:
DB::enableQueryLog();

$user = DB::table("users")->get();

$query = DB::getQueryLog();

$query = end($query);

dd($query);

For processes taking a long time in MYSQL
Prepend the mysql command with EXPLAIN. The rows column shows you can many rows the command has to search through to find the result. If the number of rows is large then you may need to add an index to the appropriate column to reduce this search.

Top comments (0)