dstpabuaran.com/app/Services/Admin/Master/CustomerService.php
Yoga Pangestu 2a3e70b78d Refactor role management and pagination in admin panel
- Updated RoleIndex component to handle pagination, sorting, and searching for roles.
- Adjusted data structure for roles to include pagination details.
- Enhanced tests for various admin features (Finance, HR, Master) to validate pagination and data structure.
- Ensured all relevant tests check for data structure consistency, including total counts and pagination details.
2026-08-01 02:54:24 +07:00

42 lines
1.1 KiB
PHP

<?php
namespace App\Services\Admin\Master;
use App\Models\Customer;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Database\Eloquent\Collection;
class CustomerService
{
public function getAll(): Collection
{
return Customer::select('id', 'name', 'phone_number', 'address')->latest()->get();
}
public function paginated(int $perPage = 15, string $search = '', string $sort = 'created_at', string $direction = 'desc'): LengthAwarePaginator
{
return Customer::query()
->select('id', 'name', 'phone_number', 'address')
->when($search, fn ($q) => $q->where('name', 'like', "%{$search}%"))
->orderBy($sort, $direction)
->paginate($perPage);
}
public function create(array $data): Customer
{
return Customer::create($data);
}
public function update(Customer $customer, array $data): Customer
{
$customer->update($data);
return $customer;
}
public function delete(Customer $customer): bool
{
return $customer->delete();
}
}