fix : 모델 및 자재관리 수정
This commit is contained in:
@@ -46,7 +46,7 @@ public function getMaterials(array $params)
|
||||
});
|
||||
}
|
||||
|
||||
$q->orderByDesc('id');
|
||||
$q->orderBy('id');
|
||||
|
||||
$perPage = $p['per_page'] ?? 20;
|
||||
$page = $p['page'] ?? null;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
// 생성
|
||||
|
||||
Reference in New Issue
Block a user