Filters API
Flexible filter system for managing service hierarchies and options
Overview
A comprehensive API for managing services with dynamic filter hierarchies. This system supports multiple filter types per service, hierarchical filter relationships, and flexible many-to-many associations between services and filter options.
4 Main Resources
- Services
- Filter Types
- Filter Options
- Service Filter Values
Full CRUD Operations
- Create resources
- Read with eager loading
- Update existing data
- Delete with cascades
Advanced Features
- Hierarchical filters
- Parent-child relationships
- Many-to-many associations
- Query filtering
Database Structure
Tables
-
services - Main services (Cleaning, Inspection, etc.)
-
filter_types - Types of filters per service
-
filter_options - Available options for each type
-
service_filter_values - Many-to-many pivot table
Relationships
- Service → hasMany FilterTypes
- Service → hasManyThrough FilterOptions
- Service → belongsToMany FilterOptions
- FilterType → belongsTo Service
- FilterType → hasMany FilterOptions
- FilterType → belongsTo FilterType (parent)
- FilterType → hasMany FilterType (children)
- FilterOption → belongsTo FilterType
- FilterOption → belongsToMany Services
Database Structure
Tables
-
services - Main services (Cleaning, Inspection, etc.)
-
filter_types - Types of filters per service
-
filter_options - Available options for each type
-
service_filter_values - Many-to-many pivot table
Relationships
- Service → hasMany FilterTypes
- Service → hasManyThrough FilterOptions
- Service → belongsToMany FilterOptions
- FilterType → belongsTo Service
- FilterType → hasMany FilterOptions
- FilterType → belongsTo FilterType (parent)
- FilterType → hasMany FilterType (children)
- FilterOption → belongsTo FilterType
- FilterOption → belongsToMany Services
| Method | Endpoint | Description | Requirements |
|---|---|---|---|
| Services | |||
| GET | /api/filters/services | List all services with optional eager loading |
|
| GET | /api/filters/services/{id} | Get single service with filter types and options |
|
| POST | /api/filters/services | Create a new service |
|
| PUT | /api/filters/services/{id} | Update existing service |
|
| DELETE | /api/filters/services/{id} | Delete service (cascades to filter types) |
|
| Filter Types | |||
| GET | /api/filters/filter-types | List filter types, optionally filtered by service |
|
| GET | /api/filters/filter-types/{id} | Get single filter type with options |
|
| POST | /api/filters/filter-types | Create a new filter type |
|
| PUT | /api/filters/filter-types/{id} | Update existing filter type |
|
| DELETE | /api/filters/filter-types/{id} | Delete filter type (cascades to options) |
|
| Filter Options | |||
| GET | /api/filters/filter-options | List filter options, optionally filtered by type |
|
| GET | /api/filters/filter-options/{id} | Get single filter option |
|
| POST | /api/filters/filter-options | Create a new filter option |
|
| PUT | /api/filters/filter-options/{id} | Update existing filter option |
|
| DELETE | /api/filters/filter-options/{id} | Delete filter option |
|
| Service Filter Values (Associations) | |||
| GET | /api/filters/service-filter-values | List all service-option associations |
|
| POST | /api/filters/service-filter-values | Create service-option association |
|
| DELETE | /api/filters/service-filter-values/{id} | Delete service-option association |
|
| Method | Endpoint | Description | Requirements |
|---|---|---|---|
| Services | |||
| GET | /api/filters/services | List all services with optional eager loading |
|
| GET | /api/filters/services/{id} | Get single service with filter types and options |
|
| POST | /api/filters/services | Create a new service |
|
| PUT | /api/filters/services/{id} | Update existing service |
|
| DELETE | /api/filters/services/{id} | Delete service (cascades to filter types) |
|
| Filter Types | |||
| GET | /api/filters/filter-types | List filter types, optionally filtered by service |
|
| GET | /api/filters/filter-types/{id} | Get single filter type with options |
|
| POST | /api/filters/filter-types | Create a new filter type |
|
| PUT | /api/filters/filter-types/{id} | Update existing filter type |
|
| DELETE | /api/filters/filter-types/{id} | Delete filter type (cascades to options) |
|
| Filter Options | |||
| GET | /api/filters/filter-options | List filter options, optionally filtered by type |
|
| GET | /api/filters/filter-options/{id} | Get single filter option |
|
| POST | /api/filters/filter-options | Create a new filter option |
|
| PUT | /api/filters/filter-options/{id} | Update existing filter option |
|
| DELETE | /api/filters/filter-options/{id} | Delete filter option |
|
| Service Filter Values (Associations) | |||
| GET | /api/filters/service-filter-values | List all service-option associations |
|
| POST | /api/filters/service-filter-values | Create service-option association |
|
| DELETE | /api/filters/service-filter-values/{id} | Delete service-option association |
|
Request Examples
Get All Services with Filter Types
GET /api/filters/services
{
"data": [
{
"id": 1,
"name": "Cleaning Service",
"description": "Professional cleaning services",
"is_active": true,
"filter_types": [
{
"id": 1,
"service_id": 1,
"name": "Room Type",
"type": "select",
"is_required": true,
"display_order": 1
}
]
}
]
}
Create Service
POST /api/filters/services
{
"name": "Inspection Service",
"description": "Professional property inspections",
"is_active": true
}
Create Filter Type
POST /api/filters/filter-types
{
"service_id": 1,
"name": "Property Size",
"type": "range",
"is_required": false,
"display_order": 2
}
Create Filter Option
POST /api/filters/filter-options
{
"filter_type_id": 1,
"label": "Living Room",
"value": "living_room",
"display_order": 1
}
Associate Filter Option with Service
POST /api/filters/service-filter-values
{
"service_id": 1,
"filter_option_id": 1,
"default_value": "living_room"
}
Success Response
{
"success": true,
"message": "Operation completed successfully",
"data": { ... }
}
Error Response
{
"success": false,
"message": "Validation failed",
"errors": {
"name": ["The name field is required."]
}
}
HTTP Status Codes
| Status Code | Description |
|---|---|
| 200 OK | Request successful (GET, PUT, DELETE) |
| 201 Created | Resource created successfully (POST) |
| 400 Bad Request | Invalid request format |
| 404 Not Found | Resource not found |
| 422 Unprocessable Entity | Validation failed |
| 500 Server Error | Internal server error |