[{"id":"laravelintermediate-001","courseId":"laravel-intermediate","domain":"routing-http","topic":"query() vs input()","prompt":"A form submits sort=name in its body, and the URL also contains ?sort=price. Which call reads only the value from the URL?","hint":"Only one of these calls is limited to one place a value can come from.","explain":"Request data can arrive from several places in one HTTP request, such as the address line and the body. Some accessors read everything together; others are restricted to one source.","source":"https://laravel.com/docs/requests","interaction":{"type":"single"},"options":[{"id":"a","text":"$request->query('sort')","why":"query() reads only from the URL's query string, so it returns price here."},{"id":"b","text":"$request->input('sort')","whyNot":"input() reads the whole payload, URL and body alike, so it is not limited to the URL."},{"id":"c","text":"$request->only('sort')","whyNot":"only() returns the requested keys from all of the input, not just the values from the URL."},{"id":"d","text":"$request->all()","whyNot":"all() returns every input value at once, from the URL and the body together."}],"answer":"a","explanation":"The query method retrieves values only from the query string, while input retrieves values from the entire request payload, including the query string.","concept":"The query method retrieves values only from the query string, while input retrieves values from the entire request payload, including the query string.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"POST /orders?sort=price\n\nsort=name","takeaways":["input() looks everywhere in the request; query() looks only at the URL."]},{"id":"laravelintermediate-002","courseId":"laravel-intermediate","domain":"routing-http","topic":"Route::redirect status code","prompt":"You define a redirect route and pass no status argument. Which status code does the redirect response carry by default?","hint":"The redirect helper has a default, and a third argument can override it.","explain":"A redirect route is a shortcut for sending the client elsewhere, with no controller needed. Status codes in the 3xx family say the answer lives elsewhere, and they differ in how lasting that move is.","source":"https://laravel.com/docs/routing","interaction":{"type":"single"},"options":[{"id":"a","text":"302","why":"Route::redirect returns a 302 status by default; a third argument can change it."},{"id":"b","text":"301","whyNot":"301 is what Route::permanentRedirect returns, not the default for Route::redirect."},{"id":"c","text":"200 OK","whyNot":"The default for a redirect route is 302, not a 200 response."},{"id":"d","text":"The status code of the destination page","whyNot":"The redirect route sets its own status code, 302 by default, whatever the target page is."}],"answer":"a","explanation":"Route::redirect sends a 302 status by default; a third argument sets another code, and Route::permanentRedirect sends a 301.","concept":"Route::redirect sends a 302 status by default; a third argument sets another code, and Route::permanentRedirect sends a 301.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"Route::redirect('/here', '/there');","takeaways":["Route::redirect defaults to 302; Route::permanentRedirect uses 301."]},{"id":"laravelintermediate-003","courseId":"laravel-intermediate","domain":"routing-http","topic":"Implicit model binding when no row matches","prompt":"Your route is Route::get('/users/{user}', ...) with a User type-hint on the closure. A request arrives for /users/999, and no user has id 999. What does Laravel return?","hint":"Think about what the framework does when a URL names a record that does not exist.","explain":"Route model binding turns a URL segment into a model instance before your code runs. A binding must decide what to do when the segment matches no row, and the framework has a built-in answer for that.","source":"https://laravel.com/docs/routing","interaction":{"type":"single"},"options":[{"id":"a","text":"A 404 Not Found response, generated automatically","why":"When no matching model is found, the framework generates a 404 HTTP response on its own."},{"id":"b","text":"The closure runs with $user set to null","whyNot":"Binding does not pass null; a missing model produces a 404 response instead."},{"id":"c","text":"An empty User model with id 999 is created","whyNot":"Binding only injects a model that exists; a missing one ends in a 404 response."},{"id":"d","text":"A redirect to the users index page","whyNot":"That redirect happens only if you attach missing() to the route; the default is a 404."}],"answer":"a","explanation":"If an implicitly bound model is not found, Laravel generates a 404 response unless the route defines custom behaviour with missing().","concept":"If an implicitly bound model is not found, Laravel generates a 404 response unless the route defines custom behaviour with missing().","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["A missing bound model gives a 404 by default; missing() changes that per route."]},{"id":"laravelintermediate-004","courseId":"laravel-intermediate","domain":"routing-http","topic":"Scoped nested route bindings","prompt":"A route is defined as /users/{user}/posts/{post:slug}, with a User and a Post type-hinted in the closure. For the post lookup, what does Laravel do?","hint":"Compare how a nested parameter with a custom key is treated with how its parent is treated.","explain":"Route model binding turns URL segments into model instances. An inner segment's lookup can be tied to an outer model, and the way a parameter is written changes how that lookup runs.","source":"https://laravel.com/docs/routing","interaction":{"type":"single"},"options":[{"id":"a","text":"It finds the post by slug, among that user's posts only","why":"A custom-keyed nested binding is scoped automatically, so the post must belong to the user in the URL."},{"id":"b","text":"It searches every post by slug, whichever user owns it","whyNot":"That is unscoped lookup; it happens only if the route calls withoutScopedBindings()."},{"id":"c","text":"It matches the post by id, because the slug is ignored","whyNot":"The route declares slug as the key for this parameter, so the lookup uses it."},{"id":"d","text":"It loads the post first, then the controller checks the owner","whyNot":"The scoping is part of the lookup query itself, not a check run afterwards."}],"answer":"a","explanation":"A nested parameter with a custom key is looked up through the parent's relationship, so the child is searched only among the parent's related records.","concept":"A nested parameter with a custom key is looked up through the parent's relationship, so the child is searched only among the parent's related records.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Custom-keyed nested bindings are scoped to the parent by default; withoutScopedBindings() opts out."]},{"id":"laravelintermediate-005","courseId":"laravel-intermediate","domain":"routing-http","topic":"Code after $next()","prompt":"A middleware's handle method runs $response = $next($request); and then does more work on $response. When does that second part run?","hint":"Consider where the rest of the application sits relative to that call.","explain":"Middleware wraps the work that answers a request, so its code can run at several points on the journey. The call that passes the request onward divides that journey; ask what must finish on the inner side first.","source":"https://laravel.com/docs/lifecycle","interaction":{"type":"single"},"options":[{"id":"a","text":"After the route or controller has returned its response","why":"Code after $next runs once the route or controller has returned a response, on the way back out through the middleware."},{"id":"b","text":"Before the rest of the application starts, since handle runs first","whyNot":"Code before the $next call runs before the inner layers; code after it waits for their response."},{"id":"c","text":"After the browser has received the response","whyNot":"That timing belongs to terminate(), which runs after the response is sent, not to code after $next."},{"id":"d","text":"Never, because $response is only set when handle returns early","whyNot":"Calling $next hands back the response, so the code after it does run."}],"answer":"a","explanation":"Code after $next runs on the way back out, once inner middleware and the route or controller have produced a response; terminate() is the separate hook for after sending.","concept":"Code after $next runs on the way back out, once inner middleware and the route or controller have produced a response; terminate() is the separate hook for after sending.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Code before $next() runs on the way in; code after it runs on the way out."]}]