Unit 2: Request, Routing & Responses - Practice Quiz
1 Which file serves as the entry point for all requests entering a Laravel application?
routes/web.php
server.php
config/app.php
public/index.php
2 In the Laravel Request Lifecycle, after the application instance is created, where is the incoming request sent?
3 Which directory contains the route definition files for a Laravel application?
app/Http/Routes
routes
config/routes
resources/routes
4
Which route file is intended for routes that interact with the user via a browser and includes the web middleware group?
routes/web.php
routes/api.php
routes/channels.php
routes/console.php
5 What is the correct syntax to define a basic GET route returning 'Hello World'?
Router::fetch('/', 'Hello World');
web::get('/', 'Hello World');
Route::to('/', function () { echo 'Hello World'; });
Route::get('/', function () { return 'Hello World'; });
6 Which method serves as a shortcut to register a route that responds to multiple HTTP verbs?
Route::match(['get', 'post'], '/', ...)
Route::multiple(['get', 'post'], '/', ...)
Route::many(['get', 'post'], '/', ...)
Route::combine(['get', 'post'], '/', ...)
7 How do you define a route parameter in Laravel?
?id=
[id]
{id}
:id
8
Consider the route: Route::get('/user/{id}', function ($id) { ... });. How is the $id variable populated?
request('id').
9 What syntax is used to define an optional route parameter?
{:id}
{id?}
{?id}
[id]
10 When defining an optional parameter in a route callback, what is a requirement for the callback argument?
11 How can you constrain the format of a route parameter using a regular expression?
where method.
regex method.
validate method.
constrain method.
12 Which helper function is used to return a view from a route or controller?
render()
template()
make()
view()
13 Where are view files typically stored in a Laravel application?
resources/views
app/Views
public/views
storage/views
14 What is the default file extension for Laravel Blade templates?
.php
.blade.php
.blade
.tpl
15
If a view is located at resources/views/admin/profile.blade.php, how do you reference it using the view helper?
view('admin.profile')
view('admin/profile')
view('admin-profile')
view('resources.views.admin.profile')
16
Which of the following creates a view and passes a variable named name with the value 'John'?
view('greeting', 'name' => 'John')
view('greeting', ['name' => 'John'])
view('greeting')->withName('John')
17 Which PHP function is commonly used to create an array containing variables and their values to pass to a view?
extract()
compact()
implode()
array_make()
18 Which method allows you to share a piece of data with all views in the application?
View::share('key', 'value')
View::global('key', 'value')
Response::share('key', 'value')
Route::share('key', 'value')
19
Where should View::share typically be called?
register method of a Service Provider
routes/web.php
boot method of a Service Provider
config/app.php file
20 If you return a string from a Laravel route, what happens?
21 Which method allows you to manually create a response instance with a specific status code?
return view('Content', 200);
return make('Content', 200);
return new HTTP('Content', 200);
return response('Content', 200);
22 How do you attach a header to a response using the fluent interface?
return response($content)->header('Content-Type', 'text/plain');
return response($content)->addHeader('Content-Type', 'text/plain');
return response($content)->set('Content-Type', 'text/plain');
return response($content)->with('Content-Type', 'text/plain');
23 How can you attach a cookie to a response instance?
->cookie('name', 'value', $minutes)
->withCookie('name', 'value', $minutes)
->addCookie('name', 'value', $minutes)
24 Which global helper function can be used to generate a Cookie instance to be attached to a response later?
Request::cookie()
make_cookie()
cookie()
generate_cookie()
25 What is the default duration of a cookie in Laravel if the minutes argument is omitted (in older versions) or set to default?
26 What happens to cookies generated by Laravel by default?
27 How do you return a JSON response in Laravel?
return response($data, 'json');
return json_encode($data);
return response()->json($data);
return View::json($data);
28 If you return an Eloquent model or Collection directly from a route, what does Laravel do?
29 Which method creates a redirect response?
view()
return()
redirect()
route()
30 How do you redirect the user to a specific URI path?
return Redirect::to('/home');
return redirect()->to('/home');
return redirect('/home');
31 Which helper function redirects the user to their previous location?
return old();
return previous();
return redirect()->reverse();
return back();
32 To name a route, which method do you chain onto the route definition?
->title('profile')
->alias('profile')
->name('profile')
->label('profile')
33 How do you redirect to a named route?
return redirect()->route('profile');
return redirect('profile');
return route('profile');
return redirect()->name('profile');
34 If a named route requires parameters, how are they passed in the redirect?
return redirect()->route('profile?id=1');
return redirect()->route('profile', ['id' => 1]);
return redirect()->route('profile')->with('id', $id);
return redirect()->route('profile', $id);
35 How do you redirect to a specific Controller Action?
return redirect()->call('HomeController@index');
return redirect()->method('HomeController::index');
return redirect()->action([HomeController::class, 'index']);
return redirect()->controller('HomeController@index');
36 When redirecting with Input data (to repopulate a form), which method is chained?
->withOldData()
->withInput()
->keepInput()
->saveInput()
37 How do you flash a session message (like a success notification) alongside a redirect?
return redirect('/')->message('Success');
return redirect('/')->with('status', 'Success');
return redirect('/')->session('status', 'Success');
return redirect('/')->flash('status', 'Success');
38 Which method is used to redirect to an external domain?
redirect()->external('https://google.com')
redirect()->out('https://google.com')
redirect()->to('https://google.com')
redirect()->away('https://google.com')
39
What is the primary difference between Route::get and Route::post?
Route::get is for retrieving data, Route::post is for submitting data.
Route::post does not support CSRF protection.
Route::get is faster than Route::post.
40 In a view, how do you output a variable while escaping HTML entities to prevent XSS?
{!! $variable !!}
@echo($variable)
<?= $variable ?>
{{ $variable }}
41 In a view, how do you output data without escaping HTML (e.g., rendering a bold tag)?
@raw($variable)
{{ $variable }}
@unescaped($variable)
{!! $variable !!}
42
What happens if a required route parameter {id} is missing from the URI in the browser request?
null.
43 Which status code represents a permanent redirect?
44 When defining a route group, which method is commonly used to apply a prefix to all routes within the group?
Route::prefix('admin')->group(function () { ... });
Route::group(['prefix' => 'admin'], function() { ... });
45
What is the purpose of Route::view('/url', 'viewname')?
46 How can you check if the current request corresponds to a specific named route inside a Blade view?
route()->current('name')
request()->routeIs('name')
View::is('name')
request()->isRoute('name')
47
Which middleware is automatically applied to web routes to verify the user's session token on POST requests?
TrimStrings
VerifyCsrfToken
EncryptCookies
Authenticate
48 When returning a response with a file download, which method is used?
return response()->stream($path);
return response()->file($path);
return response()->get($path);
return response()->download($path);
49 How do you define a route that handles a Fallback (404) page when no other route matches?
Route::fallback(function () { ... });
Route::missing(function () { ... });
Route::default(function () { ... });
Route::catch(function () { ... });
50 If you want to view the raw contents of a variable and stop execution immediately (often for debugging request data), which helper is used?
dd($var)
break($var)
dump($var)
stop($var)
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →