feat : Tag 모델 추가

This commit is contained in:
2025-07-29 17:20:44 +09:00
parent 33312e7a74
commit 24c85a0605
7 changed files with 101 additions and 7 deletions

View File

@@ -0,0 +1,56 @@
<?php
namespace App\Models\Commons;
use App\Models\Materials\Material;
use App\Models\Products\Bom;
use App\Models\Products\Part;
use App\Models\Products\Product;
use App\Models\Tenants\Tenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
class Tag extends Model
{
protected $fillable = ['tenant_id', 'name'];
// 테넌트 관계(옵션)
public function tenant(): BelongsTo
{
return $this->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');
}
}

View File

@@ -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');
}

View File

@@ -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();
}

View File

@@ -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');
}
}

View File

@@ -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');
}
}

View File

@@ -1,9 +1,8 @@
<?php
namespace App\Models;
namespace App\Models\Products;
use App\Models\Commons\Tag;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -18,4 +17,10 @@ public function category() {
public function partType() {
return $this->belongsTo(CommonCode::class, 'part_type_id');
}
// 태그 목록 (N:M, 폴리모픽)
public function tags()
{
return $this->morphToMany(Tag::class, 'taggable');
}
}

View File

@@ -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');
}
}