From 24c85a060597788059d805556e808624dd70122f Mon Sep 17 00:00:00 2001 From: hskwon Date: Tue, 29 Jul 2025 17:20:44 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20Tag=20=EB=AA=A8=EB=8D=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Commons/Tag.php | 56 +++++++++++++++++++++++++++++++ app/Models/MainRequest.php | 3 +- app/Models/MainRequestFlow.php | 8 +++-- app/Models/Materials/Material.php | 10 +++++- app/Models/Products/Bom.php | 13 +++++++ app/Models/Products/Part.php | 9 +++-- app/Models/Products/Product.php | 9 +++++ 7 files changed, 101 insertions(+), 7 deletions(-) create mode 100644 app/Models/Commons/Tag.php diff --git a/app/Models/Commons/Tag.php b/app/Models/Commons/Tag.php new file mode 100644 index 0000000..9e47c95 --- /dev/null +++ b/app/Models/Commons/Tag.php @@ -0,0 +1,56 @@ +belongsTo(Tenant::class); + } + + + /** + * 제품(Product)와 연결 (N:M, 폴리모픽) + */ + public function products(): MorphToMany + { + return $this->morphedByMany(Product::class, 'taggable'); + } + + /** + * 부품(Part)와 연결 (N:M, 폴리모픽) + */ + public function parts(): MorphToMany + { + return $this->morphedByMany(Part::class, 'taggable'); + } + + /** + * 자재(Material)와 연결 (N:M, 폴리모픽) + */ + public function materials(): MorphToMany + { + return $this->morphedByMany(Material::class, 'taggable'); + } + + /** + * BOM(Bill of Materials)와 연결 (N:M, 폴리모픽) + */ + public function boms(): MorphToMany + { + return $this->morphedByMany(Bom::class, 'taggable'); + } +} diff --git a/app/Models/MainRequest.php b/app/Models/MainRequest.php index bb83d92..726a55a 100644 --- a/app/Models/MainRequest.php +++ b/app/Models/MainRequest.php @@ -3,6 +3,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; class MainRequest extends Model @@ -28,7 +29,7 @@ class MainRequest extends Model /** * 전체 이력(흐름) 리스트 */ - public function flows() + public function flows(): HasMany { return $this->hasMany(MainRequestFlow::class, 'main_request_id'); } diff --git a/app/Models/MainRequestFlow.php b/app/Models/MainRequestFlow.php index 23acb43..c321d3c 100644 --- a/app/Models/MainRequestFlow.php +++ b/app/Models/MainRequestFlow.php @@ -2,7 +2,9 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; +use App\Models\MainRequest; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\MorphTo; class MainRequestFlow extends Model { @@ -26,7 +28,7 @@ class MainRequestFlow extends Model /** * 메인 업무 엔터티 */ - public function mainRequest() + public function mainRequest(): BelongsTo { return $this->belongsTo(MainRequest::class, 'main_request_id'); } @@ -34,7 +36,7 @@ public function mainRequest() /** * 폴리모픽 관계(견적, 주문, 발주 등) */ - public function flowable() + public function flowable(): MorphTo { return $this->morphTo(); } diff --git a/app/Models/Materials/Material.php b/app/Models/Materials/Material.php index 2dbcf38..7526d2f 100644 --- a/app/Models/Materials/Material.php +++ b/app/Models/Materials/Material.php @@ -2,7 +2,8 @@ namespace App\Models\Materials; -use App\Models\File; +use App\Models\Commons\File; +use App\Models\Commons\Tag; use App\Models\Qualitys\Lot; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; @@ -35,8 +36,15 @@ public function lots() return $this->hasMany(Lot::class, 'material_id'); } + // 파일 목록 (N:M, 폴리모픽) public function files() { return $this->morphMany(File::class, 'fileable'); } + + // 태그 목록 (N:M, 폴리모픽) + public function tags() + { + return $this->morphToMany(Tag::class, 'taggable'); + } } diff --git a/app/Models/Products/Bom.php b/app/Models/Products/Bom.php index 472145f..de61b4b 100644 --- a/app/Models/Products/Bom.php +++ b/app/Models/Products/Bom.php @@ -3,6 +3,7 @@ namespace App\Models\Products; use App\Models\Commons\File; +use App\Models\Commons\Tag; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; @@ -23,4 +24,16 @@ public function items() { public function image() { return $this->belongsTo(File::class, 'image_file_id'); } + + // 파일 목록 (N:M, 폴리모픽) + public function files() + { + return $this->morphMany(File::class, 'fileable'); + } + + // 태그 목록 (N:M, 폴리모픽) + public function tags() + { + return $this->morphToMany(Tag::class, 'taggable'); + } } diff --git a/app/Models/Products/Part.php b/app/Models/Products/Part.php index 7a9d7b1..447c72b 100644 --- a/app/Models/Products/Part.php +++ b/app/Models/Products/Part.php @@ -1,9 +1,8 @@ belongsTo(CommonCode::class, 'part_type_id'); } + + // 태그 목록 (N:M, 폴리모픽) + public function tags() + { + return $this->morphToMany(Tag::class, 'taggable'); + } } diff --git a/app/Models/Products/Product.php b/app/Models/Products/Product.php index dec6da5..d0b9f1e 100644 --- a/app/Models/Products/Product.php +++ b/app/Models/Products/Product.php @@ -2,6 +2,8 @@ namespace App\Models\Products; +use App\Models\Commons\File; +use App\Models\Commons\Tag; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; @@ -17,8 +19,15 @@ public function boms() { return $this->hasMany(Bom::class); } + // 파일 목록 (N:M, 폴리모픽) public function files() { return $this->morphMany(File::class, 'fileable'); } + + // 태그 목록 (N:M, 폴리모픽) + public function tags() + { + return $this->morphToMany(Tag::class, 'taggable'); + } }