Skip to main content
This guide covers the essential CRUD operations that form the foundation of working with Rest Generic Class. You’ll learn how to set up your models, services, and controllers, then perform basic operations through the REST API.

Quick Setup

Listing Records

Simple List

Get all products:
Response:

Select Specific Fields

Reduce payload size by selecting only needed fields:
Response:

Load Relations

Eager-load related data to avoid N+1 queries:
The :id,name syntax selects only specific fields from the relation. Always include foreign keys to maintain relationships.
Response:

Filtering

Equality Filters (Legacy)

Filter by exact matches using the attr parameter:

Dynamic Filters with oper

Use the powerful oper parameter for complex conditions:
Supported operators:
  • Comparison: =, !=, <, >, <=, >=
  • Pattern matching: like, not like, ilike, not ilike
  • Set operations: in, not in
  • Range: between, not between
  • Null checks: null, not null
  • Date: date, not date

Combining AND and OR

Sorting

Order results by one or more fields:

Pagination

Standard Pagination

Response:

Creating Records

Single Record

Response:

Bulk Create

Create multiple records in one request:
The key must match the lowercase MODEL constant defined in your model (product in this example).

Updating Records

Single Update

Response:

Bulk Update

Update multiple records at once:
Response:
All updates in updateMultiple are wrapped in a transaction. If validation fails on any record, the entire transaction rolls back.

Deleting Records

Delete by ID

Response:

Showing a Single Record

Retrieve a single record with optional relations:
Response:

Common Patterns

Filtered List with Relations

Combine filtering, selection, and relation loading:

Search by Name

Use the like operator for text search:

Get Active Products in Price Range

Next Steps

Advanced Filtering

Learn complex filtering with nested relations and multiple conditions

Relation Loading

Master eager loading and nested relation queries

Caching

Configure Redis, database, or file-based caching for better performance

Bulk Operations

Optimize multiple record operations with bulk endpoints

Evidence

  • File: src/Core/Controllers/RestController.php
    Lines: 79-102, 110-121, 158-176, 186-203, 211-230, 239-243, 251-268
    Shows the request parameter extraction and CRUD endpoints (index, store, update, updateMultiple, show, destroy)
  • File: src/Core/Services/BaseService.php
    Lines: 414-423, 611-627, 645-662, 664-676, 1057-1069, 1071-1079
    Implements list_all, create, update, update_multiple, destroy, and destroybyid methods
  • File: src/Core/Models/BaseModel.php
    Lines: 28-44
    Shows MODEL and RELATIONS constants used for configuration