套件名稱 : Virtualorz/ActionLog
開發年份 : 2019
gitHub連結 : https://github.com/virtualorz/actionLog
內容簡介 :
ActionLog提供一個比較簡單的方式記錄下資料新增、編輯、刪除等等的過程,只需要在新增、編輯、刪除或者有任何資料異動的時候加入一行程式碼就可以將before after值記錄下來,本套件也提供直接產生查看紀錄畫面的方法,可以在佈建後台時更快速的將log呈現頁面完成。
- Laravel:90%
- MySQL:85%
安裝方式 :#
composer require virtualorz/actionLog編輯 config/app.php
'providers' => [
...
Virtualorz\ActionLog\ActionLogServiceProvider::class
]
'aliases' => [
...
'ActionLog' => Virtualorz\ActionLog\Facades\ActionLog::class,
]發布資料 :#
php artisan vendor:publish --provider="Virtualorz\ActionLog\ActionLogServiceProvider"執行Migration :#
php artisan migrate --path=/vendor/virtualorz/actionlog/src/migrations編輯設定檔 :#
編輯 config/actionLog_logAction.php
其中,陣列包含三種類型操作動作,可自行編輯文字,但必須保留key值不變
'log_action' => [
0 => '刪除',
1 => '新增',
2 => '異動'
]方法簡介 :#
1.pushBefore($key,$value)
手動加入before資料值到陣列中,key可以重複,重複的key也會加入變成一個陣列
2.pushAfter($key,$value)
手動加入after資料值到陣列中,key可以重複,重複的key也會加入變成一個陣列 3.save($page,$action,$remark,$object = null,$target_id = null)
將before after資料寫入資料庫,其中
$page 代表的是page name,如果有使用sitemap套件可以直接帶入sitemap中的name
$action 代表的是動作id,也就是log_action中的key
$remark 可隨意寫入備註文字
$object 代表的是Laravel model物件,如果為空值才會去讀手動存下的befor after值,如果不為空則會直接存取model中提供的前後值儲存
$target_id 代表的是本次紀錄資料的id值,可填可不填,未填寫則由model物件中取得
4.logContent($id)
產生before after值比較內容view html,可以使用{!! $RESULT_HTML !!} 將logContent產稱的結果印出在view中
範例 :
手動加入before after
ctionLog::pushBefore('system_permission', system_permission::where('member_id', $request->get('id'))->get());
...
//do some thing
...
ActionLog::pushAfter('system_permission', system_permission::where('member_id', $request->get('id'))->get());
ActionLog::save(Route::getCurrentRoute()->action['parent'],0,'remark text',null,$request->get('id'));從model中取得before after
ActionLog::save(Route::getCurrentRoute()->action['parent'],2,'remark text',$system_permission);logContent產生結果

備註 : 最新版本請參考gitHub連結說明
![[作品][Laravel Package] ActionLog : 紀錄網站每筆資料操作記錄](/2019/06/28/%E4%BD%9C%E5%93%81laravel-package-actionlog-%E7%B4%80%E9%8C%84%E7%B6%B2%E7%AB%99%E6%AF%8F%E7%AD%86%E8%B3%87%E6%96%99%E6%93%8D%E4%BD%9C%E8%A8%98%E9%8C%84/feature_hu_50291878f80b8a3.webp)