[{"id":"laravelbeginner-001","courseId":"laravel-beginner","domain":"routing-http","topic":"Basic route closures","prompt":"You add Route::get('/greeting', function () { return 'Hello World'; }); and want it to get session state and CSRF protection. Which file should hold it?","hint":"Different route files are loaded for different kinds of traffic, and each gets a middleware group.","explain":"Routes live in files in the routes directory, loaded through the app's bootstrap configuration. Each file's routes join a middleware group, and that group decides which built-in features a request gets.","source":"https://laravel.com/docs/routing#basic-routing","interaction":{"type":"single"},"options":[{"id":"a","text":"routes/web.php","why":"Routes in routes/web.php are assigned the web middleware group, which provides session state and CSRF protection."},{"id":"b","text":"routes/api.php","whyNot":"Routes in routes/api.php are stateless and assigned to the api middleware group instead."},{"id":"c","text":"bootstrap/app.php","whyNot":"That file configures how route files are loaded; it is not where route definitions go."},{"id":"d","text":"app/Http/Controllers","whyNot":"Controllers hold handler methods, but a closure route like this one is defined in a route file."}],"answer":"a","explanation":"Routes are defined in route files, and each file's routes are assigned a middleware group; routes/web.php gets the web group with session state and CSRF protection.","concept":"Routes are defined in route files, and each file's routes are assigned a middleware group; routes/web.php gets the web group with session state and CSRF protection.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Put browser-facing routes in routes/web.php so they get session and CSRF support."]},{"id":"laravelbeginner-002","courseId":"laravel-beginner","domain":"routing-http","topic":"Route parameters","prompt":"A team defines GET /user/{id} with where('id', '[0-9]+'). A request to /user/abc arrives. Which TWO statements about route parameters are correct?","hint":"Think about how values reach the callback, and what the router does when a URI breaks a constraint.","explain":"A route parameter is a slice of the URI, captured in braces and passed to the callback. Think about how values reach the callback's arguments and what a constraint does with a non-matching URI.","source":"https://laravel.com/docs/routing#route-parameters","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"Arguments are matched to parameters by position, so a variable can be named differently from the {} placeholder.","why":"Laravel injects route parameters by their order; the callback's argument names do not have to match."},{"id":"b","text":"A URI that breaks the where() constraint gets a 404 HTTP response.","why":"If the request does not match the pattern constraints, the router returns a 404 response."},{"id":"c","text":"Dependencies such as Request must be listed after the route parameters.","whyNot":"The docs say to list route parameters after dependencies, not the other way round."},{"id":"d","text":"Parameter names may contain hyphens, such as {order-id}.","whyNot":"Parameters should be alphabetic; underscores are also allowed, but a hyphen is not one of those."},{"id":"e","text":"A URI that breaks the where() constraint gets a 400 Bad Request response.","whyNot":"A failed constraint returns a 404, not a 400 Bad Request."},{"id":"f","text":"An optional {name?} parameter needs no default value on its callback argument.","whyNot":"The callback variable for an optional parameter should be given a default value."}],"answer":"ab","explanation":"Route parameters are injected by position, so argument names are free; a non-matching constraint returns a 404; parameters follow dependencies and optional ones need defaults.","concept":"Route parameters are injected by position, so argument names are free; a non-matching constraint returns a 404; parameters follow dependencies and optional ones need defaults.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["A failed where() constraint returns 404, and parameters come after injected dependencies."]},{"id":"laravelbeginner-003","courseId":"laravel-beginner","domain":"routing-http","topic":"Named routes","prompt":"You define Route::get('/user/{id}/profile', ...)->name('profile'). Which call builds http://example.com/user/1/profile?photos=yes?","hint":"Named routes are reached through a helper that takes the name first.","explain":"A name gives a route a stable handle, so code can build its address without copying the path. Values you supply fill the path's placeholders, and any leftover values end up in the final address.","source":"https://laravel.com/docs/routing#named-routes","interaction":{"type":"single"},"options":[{"id":"a","text":"route('profile', ['id' => 1, 'photos' => 'yes'])","why":"The parameters go in the second argument, and extra key/value pairs are appended to the query string."},{"id":"b","text":"route('/user/{id}/profile', ['id' => 1, 'photos' => 'yes'])","whyNot":"route() takes the route's name, not its URI."},{"id":"c","text":"route('profile', ['id' => 1], ['photos' => 'yes'])","whyNot":"Additional values belong in the same array as the parameters, not in a separate one."},{"id":"d","text":"url('profile', ['id' => 1, 'photos' => 'yes'])","whyNot":"url() is not the named-route helper; the docs generate named-route URLs with route()."}],"answer":"a","explanation":"route() generates a URL from a route's name; the second argument fills parameters, and extra key/value pairs become the query string.","concept":"route() generates a URL from a route's name; the second argument fills parameters, and extra key/value pairs become the query string.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Generate URLs with route('name', [...]); extra array keys become query string values."]},{"id":"laravelbeginner-004","courseId":"laravel-beginner","domain":"routing-http","topic":"Basic controllers","prompt":"A team sets up a resource controller for photos. Put these steps in the order the Laravel docs describe them.","hint":"Ask what each step depends on before it can happen.","explain":"Setting up a resource controller involves stages that each depend on something produced earlier. Ask what each stage needs before it can happen, and what the declaration itself ends up creating.","source":"https://laravel.com/docs/controllers#resource-controllers","interaction":{"type":"sort","items":[{"text":"Run make:controller PhotoController --resource","why":"The generator creates the controller class first, so there is code for routes to point at."},{"text":"The generated controller has a stub for each resource action","why":"The generator fills the class with stubbed methods, and those exist before any route is declared."},{"text":"Register Route::resource('photos', PhotoController::class)","why":"The route declaration points at the controller class, which must already exist."},{"text":"That one declaration creates several routes for the actions","why":"Those routes come from the declaration, so they exist only after it is registered."}]},"options":[],"answer":"o:abcd","explanation":"make:controller with --resource generates a controller with a stubbed method for each resource action; registering Route::resource then creates the routes for those actions.","concept":"make:controller with --resource generates a controller with a stubbed method for each resource action; registering Route::resource then creates the routes for those actions.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Generate the resource controller first, then register Route::resource to create its routes."]},{"id":"laravelbeginner-005","courseId":"laravel-beginner","domain":"routing-http","topic":"Resource controllers","prompt":"You are building a JSON API for photos and want no routes that show HTML forms. Which registration leaves out the create and edit routes?","hint":"Look at which routes present HTML templates, and at the registration variant meant for APIs.","explain":"Resource routing creates a standard set of routes for a controller, and some of them present HTML templates. A separate registration exists for JSON APIs, which need only the routes that exchange data.","source":"https://laravel.com/docs/controllers#resource-controllers","interaction":{"type":"single"},"options":[{"id":"a","text":"Route::apiResource('photos', PhotoController::class)","why":"apiResource registers the resource without the create and edit routes, which present HTML templates."},{"id":"b","text":"Route::resource('photos', PhotoController::class)->except(['create'])","whyNot":"except() removes only the actions listed, so the edit route would still be registered."},{"id":"c","text":"Route::resources(['photos' => PhotoController::class])","whyNot":"resources() registers many resource controllers at once with the full default set of actions, including create and edit."},{"id":"d","text":"Route::resource('photos', PhotoController::class)->withTrashed()","whyNot":"withTrashed() lets soft-deleted models be found; it does not remove any routes."}],"answer":"a","explanation":"apiResource registers a resource without the create and edit routes, which present HTML templates; a plain resource includes them.","concept":"apiResource registers a resource without the create and edit routes, which present HTML templates; a plain resource includes them.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Use apiResource for JSON APIs; it skips the create and edit routes that show HTML forms."]}]