From 028af8fbfab2fecc19179d13332af6950cc93e37 Mon Sep 17 00:00:00 2001 From: hskwon Date: Wed, 27 Aug 2025 18:13:49 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20=EB=AA=A8=EB=8D=B8=20=EB=B0=8F=20?= =?UTF-8?q?=EC=9E=90=EC=9E=AC=EA=B4=80=EB=A6=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Materials/Material.php | 5 +++++ app/Models/Products/Product.php | 6 +++++- app/Services/MaterialService.php | 2 +- app/Services/ProductService.php | 19 +++++++++++++++++-- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/app/Models/Materials/Material.php b/app/Models/Materials/Material.php index 0aaf330..8d81e07 100644 --- a/app/Models/Materials/Material.php +++ b/app/Models/Materials/Material.php @@ -7,6 +7,7 @@ use App\Models\Qualitys\Lot; use App\Traits\ModelTrait; use App\Traits\BelongsToTenant; +use Filament\Forms\Components\Hidden; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; @@ -22,6 +23,10 @@ class Material extends Model 'options' => 'array', ]; + protected $hidden = [ + 'deleted_at', + ]; + // 자재 입고 내역 public function receipts() { diff --git a/app/Models/Products/Product.php b/app/Models/Products/Product.php index e070613..df10f73 100644 --- a/app/Models/Products/Product.php +++ b/app/Models/Products/Product.php @@ -16,7 +16,7 @@ class Product extends Model protected $fillable = [ 'tenant_id','code','name','category_id', - 'product_type', // 라벨/분류용 + 'product_type', // 라벨/분류용 'attributes','description','is_active', 'is_sellable','is_purchasable','is_producible', 'created_by','updated_by' @@ -30,6 +30,10 @@ class Product extends Model 'is_producible' => 'boolean', ]; + protected $hidden = [ + 'deleted_at', + ]; + // 분류 public function category() { return $this->belongsTo(Category::class, 'category_id'); } diff --git a/app/Services/MaterialService.php b/app/Services/MaterialService.php index 246e44c..aef2309 100644 --- a/app/Services/MaterialService.php +++ b/app/Services/MaterialService.php @@ -46,7 +46,7 @@ public function getMaterials(array $params) }); } - $q->orderByDesc('id'); + $q->orderBy('id'); $perPage = $p['per_page'] ?? 20; $page = $p['page'] ?? null; diff --git a/app/Services/ProductService.php b/app/Services/ProductService.php index 100461c..b048928 100644 --- a/app/Services/ProductService.php +++ b/app/Services/ProductService.php @@ -72,7 +72,9 @@ public function index(array $params) $productType = $params['product_type'] ?? null; // PRODUCT|PART|SUBASSEMBLY... $active = $params['active'] ?? null; // 1/0 - $query = Product::query()->where('tenant_id', $tenantId); + $query = Product::query() + ->with('category:id,name') // 필요한 컬럼만 가져오기 + ->where('tenant_id', $tenantId); if ($q !== '') { $query->where(function ($w) use ($q) { @@ -85,7 +87,20 @@ public function index(array $params) if ($productType) $query->where('product_type', $productType); if ($active !== null && $active !== '') $query->where('is_active', (int)$active); - return $query->orderByDesc('id')->paginate($size); + $paginator = $query->orderBy('id')->paginate($size); + + // 날짜 형식을 위해 분리 + $paginator->setCollection( + $paginator->getCollection()->transform(function ($item) { + $arr = $item->toArray(); + $arr['created_at'] = $item->created_at + ? $item->created_at->format('Y-m-d') + : null; + return $arr; + }) + ); + + return $paginator; } // 생성