Browse Source

created_by,updated_by

peterguo 6 days ago
parent
commit
f20e512642

+ 3 - 1
app/Http/Controllers/API/FolderController.php

@@ -128,6 +128,7 @@ class FolderController extends Controller
 
 
             if ($isUpdate) {
             if ($isUpdate) {
                 $folder = $updateFolders[$item['id']];
                 $folder = $updateFolders[$item['id']];
+                $data['updated_by'] = Auth::user()->id;
                 $folder->fill($data);
                 $folder->fill($data);
                 $folder->save();
                 $folder->save();
             } else {
             } else {
@@ -135,7 +136,8 @@ class FolderController extends Controller
                     'company_id' => Auth::user()->company_id,
                     'company_id' => Auth::user()->company_id,
                     ...$objectWhere,
                     ...$objectWhere,
                     'parent_id' => $request->parent_id,
                     'parent_id' => $request->parent_id,
-                    ...$data
+                    ...$data,
+                    'created_by' => Auth::user()->id,
                 ]);
                 ]);
 
 
                 $folder->path = $parentFolder ? $parentFolder?->path . $folder->id . "," : sprintf(",%s,", $folder->id);
                 $folder->path = $parentFolder ? $parentFolder?->path . $folder->id . "," : sprintf(",%s,", $folder->id);

+ 2 - 0
app/Services/File/FileService.php

@@ -8,6 +8,7 @@ use App\Models\File;
 use App\Repositories\ActionRepository;
 use App\Repositories\ActionRepository;
 use App\Repositories\CustomFieldRepository;
 use App\Repositories\CustomFieldRepository;
 use App\Services\History\ModelChangeDetector;
 use App\Services\History\ModelChangeDetector;
+use Illuminate\Support\Facades\Auth;
 
 
 class FileService
 class FileService
 {
 {
@@ -20,6 +21,7 @@ class FileService
     public function update(string $id, array $updatedData): void
     public function update(string $id, array $updatedData): void
     {
     {
         $file = File::query()->findOrFail($id);
         $file = File::query()->findOrFail($id);
+        $updatedData['updated_by'] = Auth::user()->id;
         $file->fill($updatedData);
         $file->fill($updatedData);
 
 
         $changes = ModelChangeDetector::detector(ActionObjectType::CONTAINER_FILE, $file);
         $changes = ModelChangeDetector::detector(ActionObjectType::CONTAINER_FILE, $file);

+ 30 - 0
database/migrations/tenant/2025_02_05_160814_add_columns_to_files_table.php

@@ -0,0 +1,30 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::table('files', function (Blueprint $table) {
+            //
+            $table->integer('updated_by')->nullable();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::table('files', function (Blueprint $table) {
+            //
+            $table->dropColumn('updated_by');
+        });
+    }
+};

+ 32 - 0
database/migrations/tenant/2025_02_05_160852_add_columns_to_folders_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::table('folders', function (Blueprint $table) {
+            //
+            $table->integer('created_by')->nullable();
+            $table->integer('updated_by')->nullable();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::table('folders', function (Blueprint $table) {
+            //
+            $table->dropColumn('created_by');
+            $table->dropColumn('updated_by');
+        });
+    }
+};