big update base struktur tahap 1
This commit is contained in:
@@ -6,16 +6,29 @@ use App\Models\TicketIncidentType;
|
||||
|
||||
class TicketIncidentTypeService
|
||||
{
|
||||
public function getAll()
|
||||
public function list(array $filters = [])
|
||||
{
|
||||
return TicketIncidentType::orderBy('name')->get();
|
||||
return TicketIncidentType::query()
|
||||
->when(
|
||||
! empty($filters['search']),
|
||||
fn ($query) => $query->where('name', 'ILIKE', "%{$filters['search']}%")
|
||||
)
|
||||
->when(
|
||||
array_key_exists('is_active', $filters) && $filters['is_active'] !== '',
|
||||
fn ($query) => $query->where(
|
||||
'is_active',
|
||||
filter_var($filters['is_active'], FILTER_VALIDATE_BOOLEAN)
|
||||
)
|
||||
)
|
||||
->orderBy('name')
|
||||
->paginate($filters['per_page'] ?? 10);
|
||||
}
|
||||
|
||||
public function create(array $data): TicketIncidentType
|
||||
{
|
||||
return TicketIncidentType::create([
|
||||
'name' => $data['name'],
|
||||
'is_active' => $data['is_active'] ?? true
|
||||
'is_active' => $data['is_active'] ?? true,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -25,7 +38,7 @@ class TicketIncidentTypeService
|
||||
): TicketIncidentType {
|
||||
$ticketIncidentType->update([
|
||||
'name' => $data['name'],
|
||||
'is_active' => $data['is_active']
|
||||
'is_active' => $data['is_active'],
|
||||
]);
|
||||
|
||||
return $ticketIncidentType->fresh();
|
||||
@@ -35,4 +48,4 @@ class TicketIncidentTypeService
|
||||
{
|
||||
$ticketIncidentType->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user