General Usage
Does this package register routes for me?
Does this package register routes for me?
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 This gives you complete flexibility over URL structure, middleware, and route organization.
RestController:Can I use MongoDB with this package?
Can I use MongoDB with this package?
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.Is Spatie permission package required?
Is Spatie permission package required?
No. Spatie’s If you don’t install Spatie, you can still use the package’s core CRUD, filtering, and relation-loading features.
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.Does the package support hierarchical tree structures?
Does the package support hierarchical tree structures?
Yes! Hierarchy support is built-in when your model defines the Request example:See the Hierarchy documentation for all available modes and options.
HIERARCHY_FIELD_ID constant and you pass the hierarchy parameter in requests.Performance
How does caching work?
How does caching work?
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_allandget_oneoperations - 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=falseorcache_ttl=120parameters
Accept-Language and X-Tenant-Id headers to prevent cross-tenant data leaks.See the Cache strategy for complete caching options.What are the performance limits for filtering?
What are the performance limits for filtering?
The package includes built-in safety limits to protect your database:
These limits prevent abusive queries with excessive complexity.You can adjust them in
| Limit | Default | Config Key |
|---|---|---|
| Maximum nesting depth | 5 | filtering.max_depth |
| Maximum conditions | 100 | filtering.max_conditions |
config/rest-generic-class.php:How can I optimize queries with many relations?
How can I optimize queries with many relations?
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
Can I use different cache stores for different models?
Can I use different cache stores for different models?
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:
How do I enable query logging?
How do I enable query logging?
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.
Why aren't my environment variable changes working?
Why aren't my environment variable changes working?
If you’re using Laravel’s config caching (common in production), environment variables are cached.After changing 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.
.env, clear the config cache:Development
Does the package include tests?
Does the package include tests?
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
RestControllersubclasses - Tests for
operfiltering and relation allowlist enforcement - Tests for hierarchy listing if you use
HIERARCHY_FIELD_ID - Authorization tests if using Spatie permissions
Can I extend or override the base classes?
Can I extend or override the base classes?
Absolutely! The package is designed for extension:You have complete control over extending functionality while benefiting from the base features.
How do I contribute to the package?
How do I contribute to the package?
Contributions are welcome!
- Open issues on GitHub for bugs or feature requests
- Submit pull requests with improvements
- For security concerns, report them privately to the maintainer
Need More Help?
Still have questions?- Check the Troubleshooting guide for common errors
- Review the API Reference for detailed documentation
- Browse Usage examples for practical implementations
- Open an issue on GitHub