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

7
  • Maybe related stackoverflow.com/questions/41140975/… Commented Nov 20, 2018 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. Commented Nov 20, 2018 at 20:48
  • You can take @Hackerman's suggestion and put it in a service provider which logs everything. Commented Nov 20, 2018 at 20:50
  • You didn't state what SQL engine you're using, but if it's MySQL you can try this stackoverflow.com/questions/303994/log-all-queries-in-mysql Commented Nov 20, 2018 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? Commented Nov 20, 2018 at 21:20

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.