- How do I install and enable Grease in a Laravel 10+ project?
- Run `composer require onelearningcommunity/grease`, then add the service provider to `config/app.php` under `providers`. No additional configuration is needed—optimizations are opt-in via facade methods like `Grease::optimizeQuery()` or `Grease::hydrateLazy()`.
- Which Laravel Eloquent operations does Grease optimize?
- Grease targets the 'hot path' of Eloquent: query building (e.g., `where()`, `with()`), hydration (model instantiation), and eager loading. It avoids write operations, focusing on read-heavy workflows like APIs or admin dashboards.
- Will Grease break existing Eloquent behavior or third-party packages?
- No—Grease produces byte-identical output and doesn’t modify core Eloquent. However, packages that hook into internals (e.g., query observers, global scopes) *might* conflict. Test with `tntsearch/laravel-scout-dog` or Laravel Debugbar before full adoption.
- Does Grease work with Laravel 9 or older versions?
- Grease officially supports Laravel 10+. For older versions, you’d need to fork the package (not recommended) or upgrade Laravel. The effort is justified for performance-critical apps, as optimizations are minimal-risk due to zero-core changes.
- How do I measure Grease’s impact on query performance?
- Use Laravel Debugbar or Blackfire to compare pre/post-optimization metrics. Focus on hydration time (e.g., `Model::all()`) and eager loading (`with()`). For APIs, track response times with tools like New Relic or Datadog.
- Are there any memory tradeoffs with Grease’s optimizations?
- Some optimizations (e.g., lazy hydration) may increase memory usage for complex queries. Monitor with `laravel-debugbar` or Blackfire, especially in high-concurrency environments. Profile before enabling optimizations for critical models.
- Can I A/B test Grease optimizations before full rollout?
- Yes. Use feature flags (e.g., `spatie/laravel-feature-flags`) to enable Grease only for specific routes or models. Start with non-critical endpoints (e.g., `/api/v1/products`) and monitor for regressions before full adoption.
- Does Grease support GraphQL or real-time systems like Livewire?
- Grease is less ideal for GraphQL (e.g., Laravel GraphQL resolvers) or real-time systems (WebSockets/Livewire) due to hydration conflicts. Test thoroughly if your app relies on these—optimizations may not apply or could introduce edge cases.
- What if a Grease optimization conflicts with a custom Eloquent macro?
- Grease prioritizes safety and will skip optimizations that detect macro/global scope conflicts. Log warnings via `Grease::getSkippedOptimizations()` to identify affected queries. Mitigate by excluding specific models or adjusting macros.
- How do I handle production rollouts if Grease causes unexpected issues?
- Roll out in phases: Start with low-traffic models, then high-traffic endpoints. Use canary releases (e.g., 10% of traffic) and monitor error rates with Sentry or Laravel’s exception logging. Always have a fallback plan to disable Grease via config.