Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
Which file serves as the entry point for all requests entering a Laravel application?
Not quite. Try another option.
Answer: public/index.php
The public/index.php file is the entry point for all requests. It loads the Composer autoloader and retrieves an instance of the Laravel application from bootstrap/app.php.
Question 2 of 50
In the Laravel Request Lifecycle, after the application instance is created, where is the incoming request sent?
Not quite. Try another option.
Answer: To the HTTP Kernel or Console Kernel
Depending on the type of request, the incoming request is sent to either the HTTP Kernel (App\Http\Kernel) or the Console Kernel.
Question 3 of 50
Which directory contains the route definition files for a Laravel application?
Not quite. Try another option.
Answer: routes
All route files (such as web.php, api.php, console.php, etc.) are stored in the routes directory in the root of the project.
Question 4 of 50
Which route file is intended for routes that interact with the user via a browser and includes the web middleware group?
Not quite. Try another option.
Answer: routes/web.php
routes/web.php defines routes for the web interface and applies the web middleware group, which provides features like session state and CSRF protection.
Question 5 of 50
What is the correct syntax to define a basic GET route returning 'Hello World'?
Not quite. Try another option.
Answer: Route::get('/', function () { return 'Hello World'; });
The Route::get method is used to define a route that responds to HTTP GET requests.
Question 6 of 50
Which method serves as a shortcut to register a route that responds to multiple HTTP verbs?
Not quite. Try another option.
Answer: Route::match(['get', 'post'], '/', ...)
The Route::match method allows you to register a route that responds to an array of specified HTTP verbs.
Question 7 of 50
How do you define a route parameter in Laravel?
Not quite. Try another option.
Answer: By enclosing it in curly braces: {id}
Route parameters are defined by enclosing the parameter name within curly braces, for example, Route::get('/user/{id}', ...).
Question 8 of 50
Consider the route: Route::get('/user/{id}', function ($id) { ... });. How is the $id variable populated?
Not quite. Try another option.
Answer: It takes the value of the corresponding URI segment.
Route parameters are injected into route callbacks or controllers based on their order (or name in recent versions) matching the URI segments defined in curly braces.
Question 9 of 50
What syntax is used to define an optional route parameter?
Not quite. Try another option.
Answer: {id?}
To make a route parameter optional, you place a question mark after the parameter name, e.g., {name?}.
Question 10 of 50
When defining an optional parameter in a route callback, what is a requirement for the callback argument?
Not quite. Try another option.
Answer: It must have a default value.
When a parameter is optional ({name?}), the corresponding variable in the closure or controller method must have a default value defined, e.g., function ($name = null).
Question 11 of 50
How can you constrain the format of a route parameter using a regular expression?
Not quite. Try another option.
Answer: Using the where method.
The where method allows you to constrain the format of route parameters. Example: Route::get(...)->where('id', '[0-9]+');.
Question 12 of 50
Which helper function is used to return a view from a route or controller?
Not quite. Try another option.
Answer: view()
The global view() helper function is used to generate a View instance.
Question 13 of 50
Where are view files typically stored in a Laravel application?
Not quite. Try another option.
Answer: resources/views
Laravel views are strictly stored in the resources/views directory by default.
Question 14 of 50
What is the default file extension for Laravel Blade templates?
Not quite. Try another option.
Answer: .blade.php
Laravel's templating engine, Blade, uses the .blade.php file extension.
Question 15 of 50
If a view is located at resources/views/admin/profile.blade.php, how do you reference it using the view helper?
Not quite. Try another option.
Answer: view('admin.profile')
Laravel uses dot notation to reference nested views. admin.profile corresponds to admin/profile.blade.php.
Question 16 of 50
Which of the following creates a view and passes a variable named name with the value 'John'?
Not quite. Try another option.
Answer: Both B and C are correct.
You can pass data as an array in the second argument (['name' => 'John']) or use the with method (specifically dynamic methods like withName or with('name', 'John')).
Question 17 of 50
Which PHP function is commonly used to create an array containing variables and their values to pass to a view?
Not quite. Try another option.
Answer: compact()
The compact() function creates an array containing variables and their values, which is a common, clean way to pass data to views. E.g., view('page', compact('data')).
Question 18 of 50
Which method allows you to share a piece of data with all views in the application?
Not quite. Try another option.
Answer: View::share('key', 'value')
The View::share method is used within a Service Provider (usually AppServiceProvider) to share data with all views rendered by the application.
Question 19 of 50
Where should View::share typically be called?
Not quite. Try another option.
Answer: In the boot method of a Service Provider
Calls to View::share should be placed in the boot method of a service provider (like AppServiceProvider) to ensure the view factory is loaded.
Question 20 of 50
If you return a string from a Laravel route, what happens?
Not quite. Try another option.
Answer: Laravel automatically converts the string into a full HTTP response.
Laravel detects string returns and automatically wraps them in a standard HTTP response with a 200 status code.
Question 21 of 50
Which method allows you to manually create a response instance with a specific status code?
Not quite. Try another option.
Answer: return response('Content', 200);
The response() global helper allows you to pass the content as the first argument and the HTTP status code as the second argument.
Question 22 of 50
How do you attach a header to a response using the fluent interface?
The header method is used on the response instance to add HTTP headers.
Question 23 of 50
How can you attach a cookie to a response instance?
Not quite. Try another option.
Answer: Both A and B are correct.
You can use the cookie() method on the response instance, or withCookie(). Both achieve the same result of attaching a cookie to the outgoing response.
Question 24 of 50
Which global helper function can be used to generate a Cookie instance to be attached to a response later?
Not quite. Try another option.
Answer: cookie()
The cookie() global helper (when called with arguments) generates a cookie instance that can be attached to a response.
Question 25 of 50
What is the default duration of a cookie in Laravel if the minutes argument is omitted (in older versions) or set to default?
Not quite. Try another option.
Answer: It is a session cookie (expires when browser closes).
If the expiration time is not set, the cookie is generally treated as a session cookie, expiring when the browser is closed.
Question 26 of 50
What happens to cookies generated by Laravel by default?
Not quite. Try another option.
Answer: They are encrypted and signed.
By default, Laravel encrypts and signs all cookies generated by the framework so they cannot be modified or read by the client.
Question 27 of 50
How do you return a JSON response in Laravel?
Not quite. Try another option.
Answer: return response()->json($data);
The json method on the response factory sets the Content-Type header to application/json and JSON encodes the provided array or object.
Question 28 of 50
If you return an Eloquent model or Collection directly from a route, what does Laravel do?
Not quite. Try another option.
Answer: It automatically converts it to JSON.
Laravel automatically serializes Eloquent models and collections to JSON when they are returned directly from a route or controller action.
Question 29 of 50
Which method creates a redirect response?
Not quite. Try another option.
Answer: redirect()
The global redirect() helper is used to generate a RedirectResponse instance.
Question 30 of 50
How do you redirect the user to a specific URI path?
Not quite. Try another option.
Answer: All of the above.
All listed options are valid ways to redirect to a path. The redirect('/home') helper is the most common shorthand.
Question 31 of 50
Which helper function redirects the user to their previous location?
Not quite. Try another option.
Answer: return back();
The back() global helper generates a redirect response to the user's previous location.
Question 32 of 50
To name a route, which method do you chain onto the route definition?
Not quite. Try another option.
Answer: ->name('profile')
The name method is used to assign a specific name to a route, e.g., Route::get(...)->name('profile');.
Question 33 of 50
How do you redirect to a named route?
Not quite. Try another option.
Answer: return redirect()->route('profile');
The route method on the redirect instance is used to generate a redirect to a named route.
Question 34 of 50
If a named route requires parameters, how are they passed in the redirect?
The action method on the redirect factory allows redirection to a specific controller action. Syntax: redirect()->action([Controller::class, 'method']).
Question 36 of 50
When redirecting with Input data (to repopulate a form), which method is chained?
Not quite. Try another option.
Answer: ->withInput()
The withInput() method flashes the current request's input data to the session, allowing it to be retrieved via the old() helper in the view.
Question 37 of 50
How do you flash a session message (like a success notification) alongside a redirect?
Nearly through. Did unit 2 of INT221 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 2 of INT221 save you a night before the exam?
Then you can help keep it free for the next batch. 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.