Skip to main content
Find answers to commonly asked questions about using Rest Generic Class in your Laravel applications.

General Usage

No. Rest Generic Class does not automatically register routes. You maintain full control over your routing.You register routes in your Laravel application’s route files and wire them to controllers that extend RestController:
This gives you complete flexibility over URL structure, middleware, and route organization.
Yes! The package includes a BaseModelMongo class specifically for MongoDB usage through the mongodb/laravel package.
You are responsible for installing and configuring mongodb/laravel in your application. The package provides the base model but doesn’t include MongoDB dependencies.
No. Spatie’s laravel-permission package is completely optional.The permission models, traits, and middleware are available if you choose to install spatie/laravel-permission, but the core functionality works without it.
If you don’t install Spatie, you can still use the package’s core CRUD, filtering, and relation-loading features.
Yes! Hierarchy support is built-in when your model defines the HIERARCHY_FIELD_ID constant and you pass the hierarchy parameter in requests.
Request example:
See the Hierarchy documentation for all available modes and options.

Performance

Rest Generic Class supports generic cache integration via Laravel’s cache stores (Redis, database, file, Memcached, etc.).Enable caching:
Key features:
  • Cache is applied to list_all and get_one operations
  • Cache keys include model, query params, auth user, and selected headers
  • Write operations automatically bump a model-level cache version to invalidate stale data
  • Per-request control via cache=false or cache_ttl=120 parameters
Multi-tenant aware: Cache keys vary by Accept-Language and X-Tenant-Id headers to prevent cross-tenant data leaks.See the Cache strategy for complete caching options.
The package includes built-in safety limits to protect your database:These limits prevent abusive queries with excessive complexity.You can adjust them in config/rest-generic-class.php:
Only increase these limits if you have legitimate use cases. Higher limits can impact database performance.
Use selective field loading to reduce data transfer and improve performance:
Best practices:
  • Only load relations you need
  • Use field selection (:id,name) on relations to limit columns
  • Enable caching for frequently accessed data
  • Set appropriate cache TTLs based on data volatility
  • Use pagination for large result sets

Configuration

The package uses a single cache store configured via REST_CACHE_STORE.However, you can:
  • Set different TTLs for list vs single record operations:
  • Override TTL per request:
  • Disable cache per request:
The cache version is tracked per model, so updates to one model won’t invalidate cache for other models.
Enable query logging in your environment:
Queries will be logged to storage/logs/query.log.You can also configure the general log level:
Query logging can significantly increase log file size. Use it for debugging and disable in production unless actively troubleshooting.
If you’re using Laravel’s config caching (common in production), environment variables are cached.After changing .env, clear the config cache:
Then rebuild it:
The package is fully compatible with Laravel’s config caching because all environment variables are only referenced in the config file, not directly in code.

Development

The package does not ship with automated tests.Validation should be performed in your host application with tests covering:
  • Feature tests for CRUD endpoints using your RestController subclasses
  • Tests for oper filtering and relation allowlist enforcement
  • Tests for hierarchy listing if you use HIERARCHY_FIELD_ID
  • Authorization tests if using Spatie permissions
This approach ensures tests are relevant to your specific implementation and use cases.
Absolutely! The package is designed for extension:
You have complete control over extending functionality while benefiting from the base features.
Contributions are welcome!
  1. Open issues on GitHub for bugs or feature requests
  2. Submit pull requests with improvements
  3. For security concerns, report them privately to the maintainer
See the Contributing guide for detailed guidelines.

Need More Help?

Still have questions?