[{"id":"laraveladvanced-001","courseId":"laravel-advanced","domain":"routing-http","topic":"Route caching","prompt":"Production runs with a route cache built during the last deploy. A developer adds a new route to routes/web.php, and the live site returns 404 for its URL. What explains this?","hint":"Think about when the framework reads the route definitions, compared with when you edited them.","explain":"Some framework state is compiled once and then reused on every request. That makes each request fast, but it also means edits to the source files take effect only when the compiled copy is rebuilt.","source":"https://laravel.com/docs/routing#route-caching","interaction":{"type":"single"},"options":[{"id":"a","text":"The cached route file is loaded on every request, so the new route is missing until the cache is rebuilt.","why":"The cache is a snapshot of the route table; new routes only appear after route:cache runs again."},{"id":"b","text":"Laravel reloads routes/web.php only after php artisan config:clear, so the new route stays unseen.","whyNot":"Config caching is unrelated to routes; when a route cache exists, the route table comes from it."},{"id":"c","text":"The browser cached the old 404, so a hard refresh is needed before the new route appears.","whyNot":"The 404 comes from the server's route table, not the browser's cache, so refreshing will not help."},{"id":"d","text":"route:cache compiles only the routes declared in routes/api.php, so web routes are skipped.","whyNot":"route:cache compiles every registered route, from any route file, not just the API file."}],"answer":"a","explanation":"php artisan route:cache compiles the registered routes into a file that is loaded on every request, so routes added later need a fresh cache.","concept":"php artisan route:cache compiles the registered routes into a file that is loaded on every request, so routes added later need a fresh cache.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["After adding routes in production, rebuild the route cache or the new routes will return 404."]},{"id":"laraveladvanced-002","courseId":"laravel-advanced","domain":"routing-http","topic":"Scoped implicit bindings","prompt":"A route is defined as /users/{user}/posts/{post:slug}. You want the post looked up only among that user's posts. Which TWO statements about scoped implicit binding are correct?","hint":"Two different things can change how a nested parameter is matched against its parent.","explain":"A nested parameter can be looked up across the whole table, or limited to children of a parent matched earlier in the URL. The parameter's syntax and calls on the route both decide which applies.","source":"https://laravel.com/docs/routing#implicit-model-binding-scoping","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"The custom key in {post:slug} makes Laravel look up the post through the user's posts relationship.","why":"With a custom key on a nested parameter, Laravel scopes the query to the parent using the plural relationship name."},{"id":"b","text":"Calling withoutScopedBindings() on the route turns the parent lookup off for that route only.","why":"It explicitly stops scoping, so the child model is found by its key across the whole table."},{"id":"c","text":"A plain {post} parameter nested under {user} is scoped automatically, with no extra call needed.","whyNot":"Without a custom key, child scoping needs scopeBindings(); plain nested parameters are not scoped by default."},{"id":"d","text":"scopeBindings() makes Laravel resolve the child model before the parent model is resolved.","whyNot":"Scoping adds a parent constraint to the child lookup; it does not change which model is resolved first."},{"id":"e","text":"A custom key such as {post:slug} disables parent scoping, so the post can come from any user.","whyNot":"A custom key triggers scoping rather than disabling it; withoutScopedBindings() is what disables it."},{"id":"f","text":"Scoped bindings must be listed in the route group's middleware, or the child lookup ignores the parent.","whyNot":"Scoping is set with scopeBindings() or withoutScopedBindings() on the route or group, not through middleware."}],"answer":"ab","explanation":"Laravel scopes a nested model to its parent when a custom key is used, and scopeBindings() or withoutScopedBindings() set scoping explicitly.","concept":"Laravel scopes a nested model to its parent when a custom key is used, and scopeBindings() or withoutScopedBindings() set scoping explicitly.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Nested implicit bindings scope automatically only with a custom key; use scopeBindings() for plain ones."]},{"id":"laraveladvanced-003","courseId":"laravel-advanced","domain":"routing-http","topic":"Fallback routes","prompt":"A fallback route defined with Route::fallback in routes/web.php runs before your other routes, so it can intercept a request before they see it.","hint":"Think about when a catch-all route is consulted, compared with the routes that are more specific.","explain":"A catch-all route is meant for requests that nothing else handles. The route file it sits in decides which group of middleware wraps it.","source":"https://laravel.com/docs/routing#fallback-routes","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"A fallback only runs when no other route matches, so it cannot intercept requests ahead of them."},{"id":"b","text":"False","why":"A fallback is reached only when nothing else matches the request, so it runs after the other routes."}],"answer":"b","explanation":"Route::fallback defines a route executed only when no other route matches the request; declared in routes/web.php, it also receives the web middleware group.","concept":"Route::fallback defines a route executed only when no other route matches the request; declared in routes/web.php, it also receives the web middleware group.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["A fallback route is a last resort for unmatched requests, not a route that runs ahead of others."]},{"id":"laraveladvanced-004","courseId":"laravel-advanced","domain":"routing-http","topic":"Excluding middleware","prompt":"A global middleware, EnsureTokenIsValid, is appended to the stack in bootstrap/app.php. One route then calls ->withoutMiddleware([EnsureTokenIsValid::class]). What happens on that route?","hint":"Think about which list of middleware a method called on a single route can change.","explain":"Middleware can attach at two levels: across every request, or to individual routes and groups. Each level has its own methods to add and remove entries, so ask which level a method reaches.","source":"https://laravel.com/docs/middleware#excluding-middleware","interaction":{"type":"single"},"options":[{"id":"a","text":"The middleware still runs on that route, because withoutMiddleware removes only route middleware.","why":"The method can only remove route middleware and does not apply to global middleware."},{"id":"b","text":"The middleware is skipped on that route, because withoutMiddleware removes any middleware, global or route.","whyNot":"The method reaches only middleware assigned to routes or route groups, so the global entry is unaffected."},{"id":"c","text":"Laravel rejects the route with an error, because a global middleware cannot be named in withoutMiddleware.","whyNot":"Naming the class is not an error; the call simply has no effect on global middleware."},{"id":"d","text":"The middleware is skipped, because the route's own middleware list replaces the global stack.","whyNot":"Route middleware is added alongside the global stack, and withoutMiddleware never removes global entries."}],"answer":"a","explanation":"withoutMiddleware on a route removes only route middleware; middleware appended in bootstrap/app.php is global and is not affected by it.","concept":"withoutMiddleware on a route removes only route middleware; middleware appended in bootstrap/app.php is global and is not affected by it.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["withoutMiddleware removes only route or group middleware; it cannot switch off a global middleware."]},{"id":"laraveladvanced-005","courseId":"laravel-advanced","domain":"routing-http","topic":"Work after the request","prompt":"A middleware calls $next($request) first, then does its own work on the response it gets back. That work runs after the application has handled the request.","hint":"Think about where the code sits relative to the call that passes the request onward.","explain":"Middleware form layers around the rest of the application: code placed above the call that passes the request on runs on the way in, and code placed below it runs on the way back out.","source":"https://laravel.com/docs/middleware#middleware-and-responses","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":"The page says this kind of middleware performs its task after the request is handled by the application."},{"id":"b","text":"False","whyNot":"Code placed after the $next call runs once the application has handled the request, which is exactly what the statement says."}],"answer":"a","explanation":"Code placed before the $next($request) call runs before the application handles the request; code placed after it runs once the application has handled the request.","concept":"Code placed before the $next($request) call runs before the application handles the request; code placed after it runs once the application has handled the request.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Work placed after the next-layer call runs once the application has handled the request, not before it."]}]