name = $name ?? 'default'; return $this; } //使用哪个模型或数据库名记录 public function use($modelOrDb) { $this->modelOrDb = $modelOrDb; return $this; } // 多数为user public function by($user) { $this->user = $user; return $this; } public function with($addition) { $this->addition = $addition; return $this; } //记录 public function log(string $content = '') { if ($this->modelOrDb instanceof Model) { $object = new $this->modelOrDb; } else { $object = DB::table($this->modelOrDb); } return $object->insert( [ 'name' => $this->name, 'content' => $content, 'addition' => $this->addition ?? '', 'operator_id' => empty($this->user) ? null : $this->user->getKey(), 'operator_name' => empty($this->user) ? null : $this->user->username(), 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString() ] ); } }