Skip to main content

Rest Generic Class

A Laravel package that provides base classes for building RESTful APIs with dynamic filtering, relation loading, and hierarchical data structures.

Latest VersionLaravelLicense

Key Features

RESTful CRUD

Base classes for Models, Services, and Controllers to build complete CRUD APIs in minutes

Dynamic Filtering

Advanced query filtering with operators, nested conditions, and relation constraints

Relation Loading

Eager load relations with field selection and nested filtering capabilities

Hierarchical Data

Built-in support for tree structures with parent-child relationships

Laravel Cache

Integrated caching with Redis, database, or any Laravel cache driver

Role-Based Access

Field-level restrictions based on Spatie roles and permissions

Bulk Operations

Update multiple records in a single request with validation

Custom Validation

Powerful validation rules for IDs, unique constraints, and pivot tables

Quick Example

Get a working REST API in just three files:
Product.php
use Ronu\RestGenericClass\Core\Models\BaseModel;

class Product extends BaseModel
{
    protected $fillable = ['name', 'price', 'stock', 'category_id'];
    
    const MODEL = 'product';
    const RELATIONS = ['category', 'reviews'];
    
    public function category()
    {
        return $this->belongsTo(Category::class);
    }
}
ProductService.php
use Ronu\RestGenericClass\Core\Services\BaseService;

class ProductService extends BaseService
{
    public function __construct()
    {
        parent::__construct(Product::class);
    }
}
ProductController.php
use Ronu\RestGenericClass\Core\Controllers\RestController;

class ProductController extends RestController
{
    protected $modelClass = Product::class;
    
    public function __construct(ProductService $service)
    {
        $this->service = $service;
    }
}
Then query with powerful filters:
GET /api/v1/products?select=["id","name","price"]&relations=["category:id,name"]
{
  "oper": {
    "and": ["status|=|active", "price|>=|50"]
  }
}

Get Started

Quick Start

Get up and running in 5 minutes with our quickstart guide

Core Concepts

Learn the fundamental concepts behind Rest Generic Class

API Reference

Explore the complete API documentation

Examples

Browse real-world usage examples and scenarios

Build docs developers (and LLMs) love