0

We are facing a very critical and strange issue, few data is missing after a long process. We are processing cargo data, one shipment may contain 1000 of boxes from 1000 customers. Each customers will get his own tracking number(awb number), we will be adding 1000 of shipments together in a shipment number and we will update each process using shipment number. When we update a shipment number all the associated shipments will be updated. In this process we are not updating shipper/consignee details, but after this process random shipper and consignee data is got deleted. We have analysed the entire code for 1 week and we have no clue where exactly its getting deleted. Its a production issue and we are in a very critical stage. We were not able to reproduce this issue in our environment. But this is randomly reporting from client side from different branches.

To figure out the issue we decided to add more logs and want to have a strict monitoring on the executing SQL statement. Is there anyway I have to log/save the executing queries from Laravel(both DB & Eloquent models). What I am expecting is if I add a piece of code in laravel framework class, it must log the sql query in a file/database so that we will not miss any queries.

We started analysing the logs but still no clue, Can anyone suggest how to figure out this issue?

We are using Laravel 5.5

Shiny
  • 33
  • 1
  • 8
  • Maybe related https://stackoverflow.com/questions/41140975/laravel-eloquent-display-query-log/41141045 – Hackerman Nov 20 '18 at 20:45
  • I want to observe the query from laravel framework, not from our classes, so that I will not miss any query executed in the system. – Shiny Nov 20 '18 at 20:48
  • You can take @Hackerman's suggestion and put it in a service provider which logs everything. – Joel Hinz Nov 20 '18 at 20:50
  • You didn't state what SQL engine you're using, but if it's MySQL you can try this https://stackoverflow.com/questions/303994/log-all-queries-in-mysql – Mariusz Nov 20 '18 at 20:52
  • @JoelHinz & Hackerman thanks for the suggestion, I tried that and modified AppServiceProvider::boot, but its not printing the values, it is replacing with place holder. May be its for security, but I need to know the values till this problem got resolved, any help? – Shiny Nov 20 '18 at 21:20
  • @Mariusz Yes we are using Mysql, but we dont have access to the WHM panel. :( – Shiny Nov 20 '18 at 21:21
  • @JoelHinz thank you, I printed binding and am started getting the values. This is what exactly i was expected, thank you so much – Shiny Nov 20 '18 at 22:09

1 Answers1

5

Inside app\Providers\AppServiceProvider.php write the below code. Don't forget to use Illuminate\Support\Facades\DB;

You can store this query or can log as your wish in the function.

public function boot()
{
    DB::listen(function ($query) {
        dd($query->sql);
        // $query->bindings
        // $query->time
    });
}

Refer: https://laravel.com/docs/5.5/database#listening-for-query-events

Mike Doe
  • 16,349
  • 11
  • 65
  • 88
sadaiMudiNaadhar
  • 354
  • 1
  • 12