Browse Source

资产分组加上company_id

kely 1 year ago
parent
commit
812a7f0307

+ 2 - 1
app/Http/Controllers/API/RequirementGroupController.php

@@ -28,7 +28,8 @@ class RequirementGroupController extends Controller
     public function store(CreateOrUpdateRequest $request)
     {
         RequirementGroup::create([
-            ...$request->all()
+            ...$request->all(),
+         'company_id' => Auth::user()->company_id,
         ]);
 
         return $this->created();

+ 1 - 1
app/Http/Requests/API/RequirementGroup/CreateOrUpdateRequest.php

@@ -43,7 +43,7 @@ class CreateOrUpdateRequest extends FormRequest
     {
         // 如果 parent_id 不为 0,返回 exists 规则
         if ($this->input('parent_id') != 0) {
-            return Rule::exists('requirement_groups', 'id');
+            return Rule::exists('requirement_groups', 'id')->where($this->userCompanyWhere())->where('asset_id', $this->input('asset_id'));
         }
 
         // 如果 parent_id 为 0,返回空数组以跳过 exists 验证

+ 5 - 1
app/Models/RequirementGroup.php

@@ -11,11 +11,15 @@ class RequirementGroup extends Model
     use HasFactory,Filterable;
 
     protected $fillable = [
-        'name', 'abbr_name', 'asset_id','parent_id'
+        'name', 'abbr_name', 'asset_id','parent_id','company_id'
     ];
 
     public function children()
     {
         return $this->hasMany(RequirementGroup::class, 'parent_id');
     }
+
+    public function requirement(){
+        return $this->hasMany(Requirement::class,'requirement_group_id');
+    }
 }

+ 30 - 0
database/migrations/2024_02_28_070815_add_company_id_to_requirements_groups.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('requirement_groups', function (Blueprint $table) {
+            //
+            $table->integer('company_id');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::table('requirements_groups', function (Blueprint $table) {
+            //
+            $table->dropColumn('company_id');
+        });
+    }
+};