Publishing the Configuration File
While the package works with default settings, publishing the configuration file gives you full control over its behavior.1
Publish the config file
Run the publish command:This creates
config/rest-generic-class.php in your application.2
Review the configuration
Open the published config file to see all available options:
3
Set environment variables
Add environment-specific values to your
.env file (see sections below).4
Clear config cache
If you’re using config caching, clear it after making changes:
Configuration Structure
The config file is organized into logical sections:Logging Configuration
config/rest-generic-class.php
- driver: Log channel driver (single, daily, stack, etc.)
- path: Where log files are stored
- level: Minimum log level (debug, info, warning, error)
- query: Whether to log database queries (useful for performance debugging)
Filtering Configuration
config/rest-generic-class.php
- max_depth: Maximum relation nesting depth (prevents infinite recursion)
- max_conditions: Maximum filter conditions per request (prevents query overload)
- strict_relations: Whether to validate relation names against model definitions
- allowed_operators: SQL operators permitted in filters
- validate_columns: Check if columns exist before querying
- column_cache_ttl: Cache column lists for performance (in seconds)
Validation Configuration
config/rest-generic-class.php
- cache_enabled: Whether to cache validation rules
- cache_ttl: How long to cache validation rules (in seconds)
- cache_prefix: Prefix for validation cache keys
- connection: Database connection to use for validation queries
Cache Configuration
config/rest-generic-class.php
- enabled: Master switch for caching (false by default)
- store: Cache store to use (redis, database, file, memcached, etc.)
- ttl: Default cache TTL in seconds
- ttl_by_method: Method-specific TTL overrides
- cacheable_methods: Which service methods should be cached
- vary: Headers to include in cache key (for multi-tenancy, localization)
Environment Variables
Add these variables to your.env file to customize behavior:
Basic Configuration
.env
Set
LOG_QUERY=true during development to debug slow queries, but disable it in production for performance.Caching Configuration
.env
Production Configuration
Recommended settings for production environments:.env (Production)
Development Configuration
Recommended settings for local development:.env (Development)
Testing Your Configuration
Verify your configuration is loaded correctly:Cache Store Setup
To use Redis for caching (recommended for production):1
Install Redis PHP extension
2
Configure Redis in Laravel
Ensure Redis is configured in
config/database.php:config/database.php
3
Set cache driver in .env
.env
4
Test Redis connection
Logging Setup
The package automatically registers a logging channel. View logs:The logging channel is automatically registered by the service provider. You don’t need to manually add it to
config/logging.php.Configuration Best Practices
Performance Optimization
- Enable caching in production with Redis
- Increase TTL for rarely-changing data
- Disable query logging in production
- Use column validation caching to reduce database calls
Security Considerations
- Enable strict column validation to prevent SQL injection risks
- Limit max_conditions to prevent DoS attacks
- Set appropriate max_depth to prevent infinite recursion
- Validate relations strictly in production
Multi-tenancy Support
If you’re building a multi-tenant application:config/rest-generic-class.php
Next Steps
With configuration complete, you’re ready to:- Create your first RESTful resource with BaseModel, BaseService, and RestController
- Learn about filtering to leverage dynamic query capabilities
- Explore caching strategies for optimal performance
You can always modify configuration later. Start with defaults and adjust based on your application’s needs.