$model->getOriginal(), 'new' => $model->getDirty() ] : $model->getAttributes(); DB::table('model_history')->insert([ 'model_type' => get_class($model), 'model_id' => $model->getKey(), 'user_id' => Auth::check() ? Auth::id() : null, 'action' => $action, 'changes' => json_encode($changes), 'created_at' => now(), 'updated_at' => now(), ]); } }