Reputation: 21
I am developing Laravel 5 app. In Which I want to log DB::table insert, update and deleted event with all New or changed(in case DB::table is being updated) DB::table Fields . I want simple reusable solution without writing too much of a code.
Upvotes: 2
Views: 2808
Reputation: 858
You can use DB::listen() as stated in here.
// in your AppServiceProvider
public function boot()
{
DB::listen(function ($query) {
// $query->sql
// $query->bindings
// $query->time
});
}
Upvotes: 0
Reputation: 163978
Simple solution is to use Eloquent Events.
You can bind events for all models you want globally using Service Provider:
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
User::creating(function ($user) {
// Do logging
});
}
Upvotes: 0