Interview Q&A · questions with model answers
Laravel Interview Questions
Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.
-
Most asked Why should you not call env() outside configuration files?
Because after php artisan config:cache the .env file is no longer loaded, so env() returns null everywhere except inside the cached config. Read environment values into config/*.php and use…
-
Why can whereHas be slow, and what are the alternatives?
whereHas compiles to a correlated EXISTS subquery, which can be slow on large tables without the right indexes. Alternatives include a join, whereIn with a subquery, whereRelation, or restructuring…