42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Admin\Master;
|
|
|
|
use App\Models\Supplier;
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
class SupplierService
|
|
{
|
|
public function getAll(array $filters = []): Collection
|
|
{
|
|
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'])
|
|
->when($search, fn ($q) => $q->where('name', 'like', "%{$search}%"))
|
|
->orderBy($sort, $direction)
|
|
->paginate($perPage);
|
|
}
|
|
|
|
public function store(array $data): Supplier
|
|
{
|
|
return Supplier::create($data);
|
|
}
|
|
|
|
public function update(Supplier $supplier, array $data): Supplier
|
|
{
|
|
$supplier->update($data);
|
|
|
|
return $supplier;
|
|
}
|
|
|
|
public function destroy(Supplier $supplier): bool
|
|
{
|
|
return $supplier->delete();
|
|
}
|
|
}
|