Skip to main content
This page covers edge cases, extreme scenarios, and troubleshooting strategies for production environments.

Configuration Issues

Edge Case 1: Config Caching Hides Environment Changes

Symptom: Environment variable changes (like LOG_QUERY or REST_STRICT_COLUMNS) don’t take effect. Cause: Laravel caches configuration files for performance. With cached config, .env updates are ignored until the cache is rebuilt.
1

Reproduce the Issue

  1. Set LOG_QUERY=true in .env
  2. Run php artisan config:cache
  3. Change LOG_QUERY=false in .env
  4. Observe that queries are still being logged
2

Verify Current Config

3

Clear and Rebuild Cache

Production Deployment Checklist:Always run these commands after updating .env:
Testing the Fix:

Edge Case 2: Queue Workers Use Stale Config

Symptom: Long-running queue workers behave as if old configuration is still active, even after clearing cache. Cause: Queue workers boot the application once and keep config in memory until restarted.
Best Practice - Supervisor Configuration:
/etc/supervisor/conf.d/laravel-worker.conf
Set --max-time=3600 to automatically restart workers every hour, ensuring they pick up config changes.

Safety Limits and Timeouts

Edge Case 3: Deep Hierarchy Trees Cause Timeouts

Symptom: Hierarchy listing requests timeout when working with large, deeply nested category trees. Cause: Without max_depth, the package recursively loads the entire tree, which can be thousands of records.
Advanced Solution - Paginate Root Nodes:
Performance Monitoring:

Edge Case 4: Excessive Filter Conditions Trigger Limits

Symptom: Requests fail with Maximum conditions (100) exceeded error. Cause: The filter engine enforces filtering.max_conditions to prevent database overload from complex filter trees.
Increase Limit (If Necessary):
config/rest-generic-class.php
Increasing max_conditions can impact database performance. Add indexes and monitor query execution time.
Alternative - Split Into Multiple Requests:

Concurrency Issues

Edge Case 5: Bulk Update Concurrency Collisions

Symptom: Two administrators update the same record simultaneously, and one set of changes is lost. Cause: update_multiple() applies updates row-by-row without record-level locking (last-write-wins). Reproduce the Issue:
1

Admin 1 Updates Product

2

Admin 2 Updates Same Product (Simultaneous)

3

Result

Final state depends on which request completes last. Admin 1’s price update might be lost.
Solution 1 - Optimistic Locking:
Solution 2 - Database-Level Locking:

Edge Case 6: Cache Invalidation Race Conditions

Symptom: Cached data briefly shows stale information after an update. Cause: Cache version bump happens after the database write, creating a small window where stale cache is valid. Mitigation:

Multi-Tenant Issues

Edge Case 7: Cross-Tenant Permission Leaks

Symptom: Users from one tenant can access permissions from another tenant. Cause: Spatie’s PermissionRegistrar uses a team ID to scope permissions. If not set, it falls back to a global cache key. Test the Issue:
Solution - Set Team ID in Middleware:
Register Before Authorization:

Validation Edge Cases

Edge Case 8: Invalid Relation Names

Symptom: Requests return 400 error: Relation 'internalLogs' is not allowed. Cause: The relation exists on the model but isn’t added to the RELATIONS allowlist.
Test Validation:

Edge Case 9: Invalid Filter Operators

Symptom: 400 error: Operator '~=' is not allowed. Cause: The operator isn’t in the package’s allowlist. Allowed Operators:
config/rest-generic-class.php
Add Custom Operator (Advanced):
config/rest-generic-class.php

Production Monitoring

Edge Case 10: Rate Limiting Heavy Filters

Symptom: Complex queries cause slow responses and affect other users. Solution - Add Rate Limiting:
routes/api.php
Monitor Slow Queries:

Quick Reference - Common Errors

Testing Edge Cases

Next Steps