Member-only story

Log Your Laravel Database Query Like A Pro

I Wayan Aditya Wiguna
3 min readDec 8, 2024

Post Thumbnail

When you developed Laravel application, sometime everything look like normal and ok in your development stage, but usually your application will be slower after your data grow up, let say your data in hundreds of thousands data, if your query was not good or optimize your application will be slower than before.

But i think it’s normal if you are in junior level, and after a long time your experience grow, you will know when you are doing code if this query isn’t good 😁

Ok let’s to the topic, based on my experience for log database query it have 2 method, first one use laravel pulse (https://pulse.laravel.com/) and the last one made query log manually and placing in app service provider.

1 Log From AppServiceProvider.php

Let’s start from basic, for this step you just put this code into your AppServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Log;
use DB;

class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/

public function register(): void
{
//
}

/**
* Bootstrap any application services.
*/

public function boot(): void
{
// 1 seconds
$queryLimitInSeconds = 1000;

// Enable…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

I Wayan Aditya Wiguna
I Wayan Aditya Wiguna

Written by I Wayan Aditya Wiguna

Website Developer at Dinas Komunikasi, Informatika Dan Statistik Provinsi Bali with expertise in NestJS, MySQL, Django and Laravel.

No responses yet

Write a response