Overview
BaseService is the heart of the package’s query processing engine. It provides:
- Advanced query building: Dynamic filters, relations, pagination, ordering
- CRUD operations: Create, read, update, delete with validation
- Caching layer: Configurable caching with versioning and invalidation
- Hierarchy support: Tree-structured data retrieval
- Export functionality: Excel and PDF generation
- Relation filtering: Nested queries with
whereHas
Create a service for each model by extending
BaseService and passing the model class to the constructor.Constructor
Model|string
required
The Eloquent model class (instance or class name string)
Query Methods
list_all()
array
required
Query parameters object with the following optional keys:
relations: Array or JSON string of relations to eager loadselect: Fields to select (array or comma-separated string)attr/eq: Equality filters (deprecated, useoperinstead)oper: Advanced filter conditions (see Filter Syntax)orderby: Array of['field' => 'asc'|'desc']pagination: Pagination config (see Pagination)hierarchy: Hierarchy mode config (see Hierarchy)_nested: If true, applies relation filters to eager loading
bool
default:"true"
Return JSON-serializable array (vs raw collection)
array|LengthAwarePaginator|CursorPaginator
Results depend on pagination:
- No pagination:
['data' => [...]] - With pagination:
LengthAwarePaginatororCursorPaginator - Hierarchy mode: Nested tree structure
get_one()
array
required
Same parameters as
list_all() (pagination ignored)bool
default:"true"
Return JSON-serializable array
array
['data' => Model|null]show()
array
required
relations: Relations to loadselect: Fields to selecthierarchy: Hierarchy mode (seeshowHierarchy())
mixed
required
Primary key value
Model|array
Model instance or hierarchical array structure
CRUD Methods
create()
array
required
Single record attributes OR wrapped array:
array
update()
array
required
Fields to update (partial updates supported)
mixed
required
Primary key or
fieldKeyUpdate valuebool
default:"false"
Run validation before saving
array
update_multiple()
array
required
Array of records with primary keys:
bool
default:"false"
Validate each record before saving
array
destroy()
mixed
required
Primary key value
array
destroybyid()
destroy() method (supports multiple IDs).
mixed|array
required
Single ID or array of IDs
Hierarchy Methods
showHierarchy()
array
required
Query params with
hierarchy config:mixed
required
Record ID
array
Nested tree structure based on
mode:node_only: Just the node with empty children arraywith_descendants: Node + all descendants as nested treewith_ancestors: Chain from root down to nodefull_branch: Entire branch (ancestors + node + descendants)
Export Methods
exportExcel()
array
required
Same query params as
list_all() plus:filename: Output filename (default:excel.xlsx)columns: Columns to include (default: usesselector all fillable)
BinaryFileResponse
Excel file download response
exportPdf()
array
required
Same query params plus:
filename: Output filename (default:pdf_file.pdf)template: Blade view name (default:pdf)columns: Columns to include
Response
PDF file download response
Filter Syntax (oper)
Theoper parameter supports advanced filtering with logical operators and conditions.
Structure
Supported Operators
=,!=,<,>,<=,>=like,not like,ilike,not ilikein,not inbetween,not betweendate,not datenull,not nullexists,not existsregexp,not regexp
Examples
Pagination
Standard Pagination
Cursor Pagination (Infinite Scroll)
Caching
BaseService includes a built-in caching layer with versioning.Configuration
Inconfig/rest-generic-class.php:
Cache Invalidation
Cache is automatically invalidated (version bumped) after:create()update()update_multiple()destroy()destroybyid()
Per-Request Control
Relations with Field Selection
Load relations with specific fields to optimize queries.Nested Relations
Complete Example
Related
BaseModel
Model class with validation and hierarchy support
RestController
Controller exposing service methods as REST endpoints
Filter Syntax
Complete guide to filter operators and syntax