日志数据表迁移文件

  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. class CreateLogsTable extends Migration
  6. {
  7. /**
  8. * Run the migrations.
  9. *
  10. * @return void
  11. */
  12. public function up()
  13. {
  14. Schema::create('logs', function (Blueprint $table) {
  15. $table->id();
  16. $table->string('username',50)->comment('用户名');
  17. $table->string('query')->comment('SQL语句');
  18. $table->string('para')->comment('参数');
  19. $table->timestamps();
  20. });
  21. }
  22. /**
  23. * Reverse the migrations.
  24. *
  25. * @return void
  26. */
  27. public function down()
  28. {
  29. Schema::dropIfExists('logs');
  30. }
  31. }

Log 模型文件

  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. class Log extends Model
  6. {
  7. use HasFactory;
  8. protected $guarded=[];
  9. }

存入日志记录表

  1. //启用数据操作日志
  2. DB::enableQueryLog();
  3. Book::create(['name'=>'Laravel框架']);
  4. $log['username']="admin";
  5. //(DB::getQueryLog()获取操作日志,是一个二维数组
  6. foreach(DB::getQueryLog() as $operation){
  7. $log['query']=$operation['query'];
  8. $log['para']="";
  9. foreach ($operation['bindings'] as $para){
  10. $log['para'].=$para.",";
  11. }
  12. }
  13. Log::create($log);

更多相关文章

  1. Kotlin Android(安卓)Studio入门学习研究
  2. android中常见的错误及解决办法
  3. android studio运行时报错AVD Nexus_5X_API_P is already runnin
  4. android 驱动文件权限设置
  5. Android(安卓)开发笔记1
  6. Android(安卓)Studio-Gradle项目中添加libs目录
  7. Android从远程服务器下载文件到本地sd卡中
  8. Android中的Logcat方法查看内核的日志
  9. 【JNI】 Android(安卓)JNI入门实例(Windows+Cygwin+Eclipse)

随机推荐

  1. Expecting android:screenOrientation="u
  2. [置顶] android 设置边框圆角
  3. android初识之路
  4. android中连接到指定wifi
  5. Android SystemUI任务栏修改
  6. Android外置存储器(SD卡)工具类
  7. Android istview顶部的或底部的渐变色怎
  8. 自定义进度条
  9. android中MotionEvent.ACTION_CANCEL事件
  10. A Visual Guide to Android GUI Widgets