ronu / rest-generic-class
Base Class for generic restfull api in laravel
Installs: 388
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 0
Open Issues: 0
Type:vcs
pkg:composer/ronu/rest-generic-class
Requires
- php: ^8.0
- illuminate/database: ^12.0
- illuminate/http: ^12.0
- illuminate/mail: ^12.0
- illuminate/pagination: ^12.0
- illuminate/support: ^12.0
- illuminate/validation: ^12.0
Suggests
- barryvdh/laravel-dompdf: Required for exportPdf()
- maatwebsite/excel: Required for exportExcel()
- nwidart/laravel-modules: Required for module-aware permissions
- spatie/laravel-permission: Required for permission models and traits
- dev-main
- 1.9.1
- 1.9.0
- 1.8.9
- 1.8.8
- 1.8.6
- 1.8.5
- 1.8.4
- 1.8.3
- 1.8.2
- 1.8.0
- 1.7.9
- 1.7.8
- 1.7.5
- 1.7.4
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.9
- 1.6.8
- 1.6.7
- 1.6.6
- 1.6.5
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.9
- 1.5.8
- 1.5.7
- 1.5.6
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.9
- 1.4.8
- 1.4.7
- 1.4.5
- 1.4.4
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.9
- 1.3.8
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.9
- 1.2.8
- 1.2.7
- 1.2.6
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.1
- 1.2.0
- 1.1.12
- 1.1.11
- 1.1.10
- 1.1.9
- 1.1.8
- 1.1.7
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.0.9
- 1.0.8
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- v1.0.0
- dev-codex/reestructurar-y-documentar-en-espanol
- dev-codex/analyze-pdf-export-functionality
- dev-codex/audit-and-update-documentation-for-package
- dev-codex/auditar-proyecto-laravel-12-jdrm7d
- dev-codex/auditar-proyecto-laravel-12
- dev-codex/generate-laravel-library-documentation
- dev-claude/fix-parseconditionstring-type-I4yuI
- dev-claude/add-hierarchical-listing-e9h1v
- dev-claude/document-rest-api-queries-dYvtU
- dev-codex/analyze-library-for-improvements-and-defects-7xcakv
- dev-codex/analyze-library-for-improvements-and-defects-c7mvzd
- dev-codex/analyze-library-for-improvements-and-defects-40mzuo
- dev-codex/analyze-library-for-improvements-and-defects
This package is auto-updated.
Last update: 2026-02-05 11:00:40 UTC
README
A Laravel package that provides base classes for RESTful CRUD with dynamic filtering, relation loading, and hierarchical listing.
Requirements
- PHP ^8.0
- Laravel (Illuminate components) ^12.0
Installation
composer require ronu/rest-generic-class
Publish configuration (optional)
php artisan vendor:publish --tag=rest-generic-class-config
Quickstart
1) Model
<?php namespace App\Models; 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); } public function reviews() { return $this->hasMany(Review::class); } }
2) Service
<?php namespace App\Services; use App\Models\Product; use Ronu\RestGenericClass\Core\Services\BaseService; class ProductService extends BaseService { public function __construct() { parent::__construct(Product::class); } }
3) Controller
<?php namespace App\Http\Controllers\Api; use App\Models\Product; use App\Services\ProductService; use Ronu\RestGenericClass\Core\Controllers\RestController; class ProductController extends RestController { protected $modelClass = Product::class; public function __construct(ProductService $service) { $this->service = $service; } }
4) Routes
use App\Http\Controllers\Api\ProductController; Route::prefix('v1')->group(function () { Route::apiResource('products', ProductController::class); Route::post('products/update-multiple', [ProductController::class, 'updateMultiple']); });
5) Query with filtering and relations
GET /api/v1/products?select=["id","name"]&relations=["category:id,name"]
{
"oper": {
"and": ["status|=|active", "price|>=|50"]
}
}
Configuration
Publish the config file and adjust values in config/rest-generic-class.php.
Environment variables:
LOG_LEVEL(default:debug)LOG_QUERY(default:false)REST_VALIDATE_COLUMNS(default:true)REST_STRICT_COLUMNS(default:true)
Common scenarios
1) Bulk update
POST /api/v1/products/update-multiple Content-Type: application/json { "product": [ {"id": 10, "stock": 50}, {"id": 11, "stock": 0} ] }
2) Hierarchy listing
{
"hierarchy": {
"filter_mode": "with_descendants",
"children_key": "children",
"max_depth": 3
}
}
3) Permission sync (Spatie)
POST /api/permissions/assign_roles Content-Type: application/json { "roles": ["admin"], "guard": "api", "mode": "SYNC", "perms": ["products.view", "products.create"] }
Edge scenarios
- Config caching hides env updates until you clear the config cache.
- Deep hierarchy trees can time out without
max_depth. - Excessive filter conditions trigger safety limits.
See Edge and extreme scenarios for detailed guidance.
API reference
Troubleshooting
Start with Troubleshooting for common errors such as invalid relations, operator errors, and missing optional packages.
Documentation
Contributing / Security
Please open issues and pull requests on GitHub. For security concerns, report them privately to the maintainer email listed in the package metadata.