From 2fec40d7dfb641f17e2eb57c8922876bf5933453 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Tue, 1 Feb 2022 00:00:12 -0600 Subject: [PATCH] Adds actionlog for bulk edits --- .../Assets/BulkAssetsController.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 76ad983b87..6a56e24344 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Assets; use App\Helpers\Helper; use App\Http\Controllers\CheckInOutRequest; use App\Http\Controllers\Controller; +use App\Models\Actionlog; use App\Models\Asset; use App\Models\Setting; use Illuminate\Http\Request; @@ -121,6 +122,24 @@ class BulkAssetsController extends Controller } } + $changed = []; + $asset = Asset::where('id' ,$assetId)->get(); + + foreach ($this->update_array as $key => $value) { + if ($this->update_array[$key] != $asset->toArray()[0][$key]) { + $changed[$key]['old'] = $asset->toArray()[0][$key]; + $changed[$key]['new'] = $this->update_array[$key]; + } + } + + $logAction = new Actionlog(); + $logAction->item_type = Asset::class; + $logAction->item_id = $assetId; + $logAction->created_at = date("Y-m-d H:i:s"); + $logAction->user_id = Auth::id(); + $logAction->log_meta = json_encode($changed); + $logAction->logaction('update'); + DB::table('assets') ->where('id', $assetId) ->update($this->update_array);