From 705f0d3efacc3033aced4d859804e6dea58ff9a3 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Wed, 5 Aug 2026 20:45:16 +0700 Subject: [PATCH] refactor: update select statements to use array syntax for improved readability --- app/Services/Admin/Finance/CashAccountService.php | 6 +++--- .../Admin/Finance/EmployeeAdvanceService.php | 4 ++-- app/Services/Admin/Finance/ExpenseService.php | 4 ++-- app/Services/Admin/Finance/PayrollPeriodService.php | 4 ++-- app/Services/Admin/HR/EmployeeService.php | 12 ++++++------ app/Services/Admin/HR/LeaveRequestService.php | 4 ++-- app/Services/Admin/Manage/CuttingService.php | 4 ++-- app/Services/Admin/Manage/PurchaseService.php | 8 ++++---- app/Services/Admin/Manage/RestockService.php | 6 +++--- app/Services/Admin/Manage/TransactionService.php | 8 ++++---- app/Services/Admin/Master/CategoryService.php | 4 ++-- app/Services/Admin/Master/CustomerService.php | 4 ++-- app/Services/Admin/Master/Product/ProductService.php | 4 ++-- .../Admin/Master/RawMaterial/RawMaterialService.php | 4 ++-- app/Services/Admin/Master/SupplierService.php | 4 ++-- 15 files changed, 40 insertions(+), 40 deletions(-) diff --git a/app/Services/Admin/Finance/CashAccountService.php b/app/Services/Admin/Finance/CashAccountService.php index 76a9087..2634994 100644 --- a/app/Services/Admin/Finance/CashAccountService.php +++ b/app/Services/Admin/Finance/CashAccountService.php @@ -25,7 +25,7 @@ public function __construct( public function get(): ?CashAccount { - return CashAccount::select('id', 'name', 'balance')->first(); + return CashAccount::select(['id', 'name', 'balance'])->first(); } public function getAllTransactions(array $filters = []): Collection @@ -37,7 +37,7 @@ public function getAllTransactions(array $filters = []): Collection } return $cashAccount->cashTransactions() - ->select('id', 'created_by_id', 'reference_type', 'reference_id', 'amount', 'balance_after', 'type', 'description', 'created_at') + ->select(['id', 'created_by_id', 'reference_type', 'reference_id', 'amount', 'balance_after', 'type', 'description', 'created_at']) ->with('createdBy.userProfile', 'media') ->when($filters['type'] ?? null, function ($query, $type) { $query->where('type', $type); @@ -56,7 +56,7 @@ public function paginatedTransactions(int $perPage = 25, string $search = '', st } $paginator = $cashAccount->cashTransactions() - ->select('id', 'created_by_id', 'reference_type', 'reference_id', 'amount', 'balance_after', 'type', 'description', 'created_at') + ->select(['id', 'created_by_id', 'reference_type', 'reference_id', 'amount', 'balance_after', 'type', 'description', 'created_at']) ->with('createdBy.userProfile', 'media') ->when($search, fn ($q) => $q->where('description', 'like', "%{$search}%")) ->when($filters['type'] ?? null, function ($query, $type) { diff --git a/app/Services/Admin/Finance/EmployeeAdvanceService.php b/app/Services/Admin/Finance/EmployeeAdvanceService.php index 5497aee..81be675 100644 --- a/app/Services/Admin/Finance/EmployeeAdvanceService.php +++ b/app/Services/Admin/Finance/EmployeeAdvanceService.php @@ -18,7 +18,7 @@ class EmployeeAdvanceService public function getAll(array $filters = []): Collection { - return EmployeeAdvance::select('id', 'employee_id', 'amount', 'paid_amount', 'description', 'due_date', 'status', 'created_at') + return EmployeeAdvance::select(['id', 'employee_id', 'amount', 'paid_amount', 'description', 'due_date', 'status', 'created_at']) ->with(['employee.user.userProfile']) ->latest() ->get(); @@ -27,7 +27,7 @@ public function getAll(array $filters = []): Collection public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator { return EmployeeAdvance::query() - ->select('id', 'employee_id', 'amount', 'paid_amount', 'description', 'due_date', 'status', 'created_at') + ->select(['id', 'employee_id', 'amount', 'paid_amount', 'description', 'due_date', 'status', 'created_at']) ->with(['employee.user.userProfile']) ->when($search, fn ($q) => $q->where('description', 'like', "%{$search}%")) ->orderBy($sort, $direction) diff --git a/app/Services/Admin/Finance/ExpenseService.php b/app/Services/Admin/Finance/ExpenseService.php index 5006ab2..9d2ddfa 100644 --- a/app/Services/Admin/Finance/ExpenseService.php +++ b/app/Services/Admin/Finance/ExpenseService.php @@ -24,7 +24,7 @@ public function __construct( public function getAll(array $filters = []): Collection { - return Expense::select('id', 'created_by_id', 'amount', 'description', 'created_at') + return Expense::select(['id', 'created_by_id', 'amount', 'description', 'created_at']) ->with('createdBy.userProfile', 'media') ->latest() ->get() @@ -34,7 +34,7 @@ public function getAll(array $filters = []): Collection public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator { $paginator = Expense::query() - ->select('id', 'created_by_id', 'amount', 'description', 'created_at') + ->select(['id', 'created_by_id', 'amount', 'description', 'created_at']) ->with('createdBy.userProfile', 'media') ->when($search, fn ($q) => $q->where('description', 'like', "%{$search}%")) ->orderBy($sort, $direction) diff --git a/app/Services/Admin/Finance/PayrollPeriodService.php b/app/Services/Admin/Finance/PayrollPeriodService.php index 89138c3..a1eab3d 100644 --- a/app/Services/Admin/Finance/PayrollPeriodService.php +++ b/app/Services/Admin/Finance/PayrollPeriodService.php @@ -19,7 +19,7 @@ class PayrollPeriodService public function getAll(array $filters = []): Collection { - return PayrollPeriod::select('id', 'year', 'month', 'status', 'closed_at', 'created_at') + return PayrollPeriod::select(['id', 'year', 'month', 'status', 'closed_at', 'created_at']) ->withCount('payrolls') ->withSum('payrolls', 'total_amount') ->withSum('payrolls', 'bonus_amount') @@ -38,7 +38,7 @@ public function getAll(array $filters = []): Collection public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator { return PayrollPeriod::query() - ->select('id', 'year', 'month', 'status', 'closed_at', 'created_at') + ->select(['id', 'year', 'month', 'status', 'closed_at', 'created_at']) ->withCount('payrolls') ->withSum('payrolls', 'total_amount') ->withSum('payrolls', 'bonus_amount') diff --git a/app/Services/Admin/HR/EmployeeService.php b/app/Services/Admin/HR/EmployeeService.php index 11c2002..4659ef4 100644 --- a/app/Services/Admin/HR/EmployeeService.php +++ b/app/Services/Admin/HR/EmployeeService.php @@ -14,9 +14,9 @@ public function getAll(array $filters = []): Collection return User::select(['id', 'email', 'username', 'is_active']) ->where(fn ($q) => $q->whereHas('employee')->orWhereHas('roles', fn ($rq) => $rq->where('name', 'Owner'))) ->with([ - 'userProfile' => fn ($q) => $q->select('id', 'user_id', 'full_name', 'phone_number', 'gender'), - 'employee' => fn ($q) => $q->select('id', 'user_id', 'join_date', 'employment_status', 'base_salary'), - 'roles' => fn ($q) => $q->select('id', 'name'), + 'userProfile' => fn ($q) => $q->select(['id', 'user_id', 'full_name', 'phone_number', 'gender']), + 'employee' => fn ($q) => $q->select(['id', 'user_id', 'join_date', 'employment_status', 'base_salary']), + 'roles' => fn ($q) => $q->select(['id', 'name']), ]) ->when($filters['employment_status'] ?? null, fn ($q, $status) => $q->whereHas('employee', fn ($eq) => $eq->where('employment_status', $status))) ->when(isset($filters['is_active']) && $filters['is_active'] !== '', fn ($q) => $q->where('is_active', filter_var($filters['is_active'], FILTER_VALIDATE_BOOLEAN))) @@ -31,9 +31,9 @@ public function paginated(int $perPage = 25, string $search = '', string $sort = ->select(['id', 'email', 'username', 'is_active']) ->where(fn ($q) => $q->whereHas('employee')->orWhereHas('roles', fn ($rq) => $rq->where('name', 'Owner'))) ->with([ - 'userProfile' => fn ($q) => $q->select('id', 'user_id', 'full_name', 'phone_number', 'gender'), - 'employee' => fn ($q) => $q->select('id', 'user_id', 'join_date', 'employment_status', 'base_salary'), - 'roles' => fn ($q) => $q->select('id', 'name'), + 'userProfile' => fn ($q) => $q->select(['id', 'user_id', 'full_name', 'phone_number', 'gender']), + 'employee' => fn ($q) => $q->select(['id', 'user_id', 'join_date', 'employment_status', 'base_salary']), + 'roles' => fn ($q) => $q->select(['id', 'name']), ]) ->when($search, fn ($q) => $q->whereHas('userProfile', fn ($uq) => $uq->where('full_name', 'like', "%{$search}%"))) ->when($filters['employment_status'] ?? null, fn ($q, $status) => $q->whereHas('employee', fn ($eq) => $eq->where('employment_status', $status))) diff --git a/app/Services/Admin/HR/LeaveRequestService.php b/app/Services/Admin/HR/LeaveRequestService.php index 479dde2..49772d1 100644 --- a/app/Services/Admin/HR/LeaveRequestService.php +++ b/app/Services/Admin/HR/LeaveRequestService.php @@ -14,7 +14,7 @@ class LeaveRequestService { public function getAll(array $filters = []): Collection { - return LeaveRequest::select('id', 'employee_id', 'start_date', 'end_date', 'total_days', 'status', 'created_at') + return LeaveRequest::select(['id', 'employee_id', 'start_date', 'end_date', 'total_days', 'status', 'created_at']) ->with(['employee.user.userProfile']) ->when($filters['status'] ?? null, function ($query, $status) { $query->where('status', $status); @@ -26,7 +26,7 @@ public function getAll(array $filters = []): Collection public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator { return LeaveRequest::query() - ->select('id', 'employee_id', 'start_date', 'end_date', 'total_days', 'status', 'created_at') + ->select(['id', 'employee_id', 'start_date', 'end_date', 'total_days', 'status', 'created_at']) ->with(['employee.user.userProfile']) ->when($search, fn ($q) => $q->whereHas('employee.user.userProfile', fn ($uq) => $uq->where('full_name', 'like', "%{$search}%"))) ->when($filters['status'] ?? null, function ($query, $status) { diff --git a/app/Services/Admin/Manage/CuttingService.php b/app/Services/Admin/Manage/CuttingService.php index 0a91a63..0b32f88 100644 --- a/app/Services/Admin/Manage/CuttingService.php +++ b/app/Services/Admin/Manage/CuttingService.php @@ -25,7 +25,7 @@ public function __construct( public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc'): LengthAwarePaginator { $paginator = Cutting::query() - ->select('id', 'created_by_id', 'status', 'description', 'total_material_cost', 'cost_per_unit', 'created_at') + ->select(['id', 'created_by_id', 'status', 'description', 'total_material_cost', 'cost_per_unit', 'created_at']) ->with([ 'createdBy:id', 'createdBy.userProfile:id,user_id,full_name', @@ -65,7 +65,7 @@ public function getForCreate(): array { return [ 'rawMaterials' => RawMaterial::query() - ->select('id', 'name', 'unit', 'is_active') + ->select(['id', 'name', 'unit', 'is_active']) ->with([ 'rawMaterialPrices:id,raw_material_id,variant,price,stock', ]) diff --git a/app/Services/Admin/Manage/PurchaseService.php b/app/Services/Admin/Manage/PurchaseService.php index c4f5e5c..2e026a0 100644 --- a/app/Services/Admin/Manage/PurchaseService.php +++ b/app/Services/Admin/Manage/PurchaseService.php @@ -24,13 +24,13 @@ public function __construct( public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc'): LengthAwarePaginator { $paginator = Purchase::query() - ->select('id', 'supplier_id', 'created_by_id', 'subtotal', 'discount', 'shipping_cost', 'total', 'notes', 'created_at') + ->select(['id', 'supplier_id', 'created_by_id', 'subtotal', 'discount', 'shipping_cost', 'total', 'notes', 'created_at']) ->with([ 'supplier:id,name', 'createdBy:id', 'createdBy.userProfile:id,user_id,full_name', 'purchaseItems' => fn ($q) => $q - ->select('id', 'purchase_id', 'raw_material_price_id', 'quantity', 'unit_price', 'subtotal') + ->select(['id', 'purchase_id', 'raw_material_price_id', 'quantity', 'unit_price', 'subtotal']) ->orderByRaw('(SELECT variant FROM raw_material_prices WHERE raw_material_prices.id = purchase_items.raw_material_price_id)'), 'purchaseItems.rawMaterialPrice:id,raw_material_id,variant,price,stock', 'purchaseItems.rawMaterialPrice.rawMaterial:id,name,unit', @@ -66,9 +66,9 @@ public function paginated(int $perPage = 25, string $search = '', string $sort = public function getForCreate(): array { return [ - 'suppliers' => Supplier::select('id', 'name')->latest()->get(), + 'suppliers' => Supplier::select(['id', 'name'])->latest()->get(), 'rawMaterials' => RawMaterial::query() - ->select('id', 'name', 'unit', 'is_active') + ->select(['id', 'name', 'unit', 'is_active']) ->with([ 'rawMaterialPrices:id,raw_material_id,variant,price,stock', ]) diff --git a/app/Services/Admin/Manage/RestockService.php b/app/Services/Admin/Manage/RestockService.php index bab77d2..bfd89c3 100644 --- a/app/Services/Admin/Manage/RestockService.php +++ b/app/Services/Admin/Manage/RestockService.php @@ -26,12 +26,12 @@ public function __construct( public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc'): LengthAwarePaginator { $paginator = Restock::query() - ->select('id', 'created_by_id', 'subtotal', 'total', 'notes', 'stock_type', 'created_at') + ->select(['id', 'created_by_id', 'subtotal', 'total', 'notes', 'stock_type', 'created_at']) ->with([ 'createdBy:id', 'createdBy.userProfile:id,user_id,full_name', 'restockItems' => fn ($q) => $q - ->select('id', 'restock_id', 'product_variant_id', 'quantity', 'unit_price', 'subtotal') + ->select(['id', 'restock_id', 'product_variant_id', 'quantity', 'unit_price', 'subtotal']) ->orderByRaw('(SELECT name FROM product_variants WHERE product_variants.id = restock_items.product_variant_id)'), 'restockItems.productVariant:id,product_id,name,stock,reject_stock,retail_stock', 'restockItems.productVariant.product:id,name', @@ -63,7 +63,7 @@ public function getForCreate(): array { return [ 'products' => Product::query() - ->select('id', 'name', 'status') + ->select(['id', 'name', 'status']) ->with([ 'productVariants:id,product_id,name,stock,reject_stock', 'productVariants.productPrices:id,variant_id,type,price', diff --git a/app/Services/Admin/Manage/TransactionService.php b/app/Services/Admin/Manage/TransactionService.php index 656ccc1..40c1493 100644 --- a/app/Services/Admin/Manage/TransactionService.php +++ b/app/Services/Admin/Manage/TransactionService.php @@ -41,7 +41,7 @@ public function __construct( public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator { $paginator = Order::query() - ->select('id', 'created_by_id', 'customer_id', 'marketing_id', 'order_number', 'channel', 'price_type', 'status', 'payment_type', 'subtotal', 'discount', 'nego_price', 'total_amount', 'cogs', 'notes', 'created_at') + ->select(['id', 'created_by_id', 'customer_id', 'marketing_id', 'order_number', 'channel', 'price_type', 'status', 'payment_type', 'subtotal', 'discount', 'nego_price', 'total_amount', 'cogs', 'notes', 'created_at']) ->with([ 'createdBy:id', 'createdBy.userProfile:id,user_id,full_name', @@ -96,7 +96,7 @@ public function getFilterOptions(): array 'channelOptions' => OrderChannel::toSelect(), 'paymentTypeOptions' => PaymentType::toSelect(), 'customers' => Customer::query() - ->select('id', 'name') + ->select(['id', 'name']) ->orderBy('name') ->get(), 'employees' => User::query() @@ -118,7 +118,7 @@ public function getForCreate(): array { return [ 'products' => Product::query() - ->select('id', 'name', 'status') + ->select(['id', 'name', 'status']) ->with([ 'productVariants:id,product_id,name,stock,reject_stock', 'productVariants.productPrices:id,variant_id,type,price', @@ -137,7 +137,7 @@ public function getForCreate(): array }); }), 'customers' => Customer::query() - ->select('id', 'name') + ->select(['id', 'name']) ->orderBy('name') ->get(), 'employees' => User::query() diff --git a/app/Services/Admin/Master/CategoryService.php b/app/Services/Admin/Master/CategoryService.php index 3305fca..bb49e34 100644 --- a/app/Services/Admin/Master/CategoryService.php +++ b/app/Services/Admin/Master/CategoryService.php @@ -10,13 +10,13 @@ class CategoryService { public function getAll(array $filters = []): Collection { - return Category::select('id', 'name')->latest()->get(); + return Category::select(['id', 'name'])->latest()->get(); } public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator { return Category::query() - ->select('id', 'name') + ->select(['id', 'name']) ->when($search, fn ($q) => $q->where('name', 'like', "%{$search}%")) ->orderBy($sort, $direction) ->paginate($perPage); diff --git a/app/Services/Admin/Master/CustomerService.php b/app/Services/Admin/Master/CustomerService.php index f60ce14..75c0ca2 100644 --- a/app/Services/Admin/Master/CustomerService.php +++ b/app/Services/Admin/Master/CustomerService.php @@ -10,13 +10,13 @@ class CustomerService { public function getAll(array $filters = []): Collection { - return Customer::select('id', 'name', 'phone_number', 'address')->latest()->get(); + return Customer::select(['id', 'name', 'phone_number', 'address'])->latest()->get(); } public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator { return Customer::query() - ->select('id', 'name', 'phone_number', 'address') + ->select(['id', 'name', 'phone_number', 'address']) ->when($search, fn ($q) => $q->where('name', 'like', "%{$search}%")) ->orderBy($sort, $direction) ->paginate($perPage); diff --git a/app/Services/Admin/Master/Product/ProductService.php b/app/Services/Admin/Master/Product/ProductService.php index fb145a6..7a9d557 100644 --- a/app/Services/Admin/Master/Product/ProductService.php +++ b/app/Services/Admin/Master/Product/ProductService.php @@ -21,7 +21,7 @@ public function __construct( public function getAll(array $filters = []): Collection { - $products = Product::select('id', 'name', 'slug', 'description', 'status') + $products = Product::select(['id', 'name', 'slug', 'description', 'status']) ->with([ 'categories:id,name', 'productVariants:id,product_id,name,stock,reject_stock,retail_stock', @@ -46,7 +46,7 @@ public function getAll(array $filters = []): Collection public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator { $paginator = Product::query() - ->select('id', 'name', 'slug', 'description', 'status') + ->select(['id', 'name', 'slug', 'description', 'status']) ->with([ 'categories:id,name', 'productVariants:id,product_id,name,stock,reject_stock,retail_stock', diff --git a/app/Services/Admin/Master/RawMaterial/RawMaterialService.php b/app/Services/Admin/Master/RawMaterial/RawMaterialService.php index b4c008a..deb22fc 100644 --- a/app/Services/Admin/Master/RawMaterial/RawMaterialService.php +++ b/app/Services/Admin/Master/RawMaterial/RawMaterialService.php @@ -20,7 +20,7 @@ public function __construct( public function getAll(array $filters = []): Collection { - return RawMaterial::select('id', 'name', 'unit', 'is_active') + return RawMaterial::select(['id', 'name', 'unit', 'is_active']) ->with([ 'rawMaterialPrices:id,raw_material_id,variant,price,stock', 'rawMaterialPrices.media', @@ -42,7 +42,7 @@ public function getAll(array $filters = []): Collection public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator { $paginator = RawMaterial::query() - ->select('id', 'name', 'unit', 'is_active') + ->select(['id', 'name', 'unit', 'is_active']) ->with([ 'rawMaterialPrices:id,raw_material_id,variant,price,stock', ]) diff --git a/app/Services/Admin/Master/SupplierService.php b/app/Services/Admin/Master/SupplierService.php index db2a302..bbfbf86 100644 --- a/app/Services/Admin/Master/SupplierService.php +++ b/app/Services/Admin/Master/SupplierService.php @@ -10,13 +10,13 @@ class SupplierService { public function getAll(array $filters = []): Collection { - return Supplier::select('id', 'name', 'phone_number', 'address')->latest()->get(); + return Supplier::select(['id', 'name', 'phone_number', 'address'])->latest()->get(); } public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator { return Supplier::query() - ->select('id', 'name', 'phone_number', 'address') + ->select(['id', 'name', 'phone_number', 'address']) ->when($search, fn ($q) => $q->where('name', 'like', "%{$search}%")) ->orderBy($sort, $direction) ->paginate($perPage);