The make:controller command is the standard Artisan command used to scaffold a new controller class.
Incorrect! Try again.
2In a controller method, what is the primary mechanism for accessing data submitted via an HTTP POST request?
A.Using the $_POST superglobal directly
B.Reading from php://input
C.Type-hinting the Illuminate\Http\Request class
D.Using the Input::get() facade only
Correct Answer: Type-hinting the Illuminate\Http\Request class
Explanation:
MVC frameworks like Laravel utilize dependency injection. Type-hinting the Request object allows you to access input data securely and cleanly.
Incorrect! Try again.
3Which method is automatically called when a controller is instantiated, often used to register middleware?
A.register()
B.boot()
C.init()
D.__construct()
Correct Answer: __construct()
Explanation:
The __construct() method is the PHP constructor where controller-specific middleware is often defined using $this->middleware().
Incorrect! Try again.
4What is a Single Action Controller?
A.A controller containing only an __invoke method
B.A controller that can only handle GET requests
C.A controller that cannot use middleware
D.A controller that does not extend the base Controller class
Correct Answer: A controller containing only an __invoke method
Explanation:
Single action controllers are classes with a single __invoke method, allowing you to route to the controller class itself without specifying a method name.
Incorrect! Try again.
5When generating a Resource Controller, which flag is added to the artisan command?
A.--restful
B.--crud
C.--resource
D.--all
Correct Answer: --resource
Explanation:
The --resource flag instructs the framework to generate a controller with methods for all standard CRUD operations (index, create, store, show, edit, update, destroy).
Incorrect! Try again.
6Which of the following methods is NOT included in an API Resource Controller (generated with --api)?
A.edit
B.index
C.destroy
D.store
Correct Answer: edit
Explanation:
API Resource controllers exclude methods that serve HTML forms, specifically create and edit, as APIs typically deal with JSON data, not view rendering.
Incorrect! Try again.
7Which routing statement creates routes for all seven standard resource actions at once?
Route::resource creates multiple routes to handle a variety of RESTful actions on the resource.
Incorrect! Try again.
8In the context of Controller Routing, what does the syntax [UserController::class, 'show'] represent?
A.A route group definition
B.The controller class and the specific method to execute
C.An array of middleware to apply
D.A resource definition
Correct Answer: The controller class and the specific method to execute
Explanation:
This array syntax is used in route definitions to specify which controller and which method within that controller should handle the request.
Incorrect! Try again.
9What file extension is strictly required for Blade templates?
A..php
B..blade
C..blade.php
D..tpl.php
Correct Answer: .blade.php
Explanation:
The Blade templating engine specifically looks for files ending in .blade.php to parse directives.
Incorrect! Try again.
10Which Blade syntax is used to echo data while automatically escaping special characters to prevent XSS attacks?
A.<?= $data ?>
B.@echo($data)
C.{!! $data !!}
D.{{ $data }}
Correct Answer: {{ $data }}
Explanation:
The double curly brace syntax {{ }} passes data through htmlspecialchars to prevent XSS.
Incorrect! Try again.
11If you need to display unescaped HTML data in Blade, which syntax should be used?
A.{{-- $data --}}
B.@raw($data)
C.{{ $data }}
D.{!! $data !!}
Correct Answer: {!! $data !!}
Explanation:
The {!! !!} syntax echoes data raw without escaping it. This should be used with caution.
Incorrect! Try again.
12Which directive is used to define a placeholder in a layout file that child views can inject content into?
A.@include
B.@extends
C.@yield
D.@section
Correct Answer: @yield
Explanation:
@yield is used in a layout template to define a section where content from a child view will be inserted.
Incorrect! Try again.
13Which directive is used at the beginning of a child view to specify which layout it inherits from?
A.@extends
B.@layout
C.@template
D.@parent
Correct Answer: @extends
Explanation:
@extends('layout.name') specifies the parent layout file that the current view inherits.
Incorrect! Try again.
14What is the correct syntax for a Blade comment that will not be rendered in the HTML source?
A./ Comment /
B.{{-- Comment --}}
C.// Comment
D.<!-- Comment -->
Correct Answer: {{-- Comment --}}
Explanation:
Blade comments {{-- --}} are stripped out by the template engine and are not sent to the browser.
Incorrect! Try again.
15Inside a @foreach loop in Blade, what special variable is automatically available to check the current iteration state?
A.$index
B.$foreach
C.$iterator
D.$loop
Correct Answer: $loop
Explanation:
The $loop variable provides properties like first, last, even, odd, and iteration inside a foreach loop.
Incorrect! Try again.
16Which Blade directive functions as the inverse of @if (executes if the condition is false)?
A.@empty
B.@else
C.@unless
D.@ifnot
Correct Answer: @unless
Explanation:
@unless(condition) is equivalent to @if(!condition).
Incorrect! Try again.
17How do you include a sub-view partials/header.blade.php inside another view?
A.@include('partials.header')
B.@yield('partials.header')
C.@import('partials.header')
D.@require('partials.header')
Correct Answer: @include('partials.header')
Explanation:
The @include directive is used to include other Blade views within a template.
Incorrect! Try again.
18Which directive allows you to define a block of JavaScript that will remain untouched by the Blade engine (useful for JS frameworks)?
A.@verbatim
B.@raw
C.@javascript
D.@literal
Correct Answer: @verbatim
Explanation:
The @verbatim directive wraps content so that Blade does not attempt to parse curly braces, allowing JS frameworks like Vue to handle them.
Incorrect! Try again.
19When defining content for a section, what directive is used to append content to the parent's section rather than overwriting it?
A.@append
B.@super
C.@base
D.@parent
Correct Answer: @parent
Explanation:
Using @parent within a @section directive appends the content to the layout's existing content for that section.
Incorrect! Try again.
20What is the primary benefit of using Named Routes?
A.They make the URL shorter.
B.They allow URL generation independent of the actual URI path.
C.They are processed faster by the server.
D.They automatically apply security headers.
Correct Answer: They allow URL generation independent of the actual URI path.
Explanation:
Named routes allow you to refer to routes by a specific name (e.g., in redirects or links). If the URL path changes, you don't need to update the links across the application.
The where method accepts the parameter name and a regular expression to constrain the format of the parameter.
Incorrect! Try again.
23Which method is used to define a group of routes that share common attributes like middleware or prefixes?
A.Route::group(...)
B.Route::batch(...)
C.Route::collection(...)
D.Route::bundle(...)
Correct Answer: Route::group(...)
Explanation:
Route::group allows you to share attributes, such as middleware, namespaces, or prefixes, across a large number of routes without defining them on each individual route.
Incorrect! Try again.
24Consider the code: Route::prefix('admin')->group(...). If a route inside the group is /dashboard, what is the resulting URL?
A./admin/dashboard
B./admin-dashboard
C./dashboard
D./dashboard/admin
Correct Answer: /admin/dashboard
Explanation:
The prefix method prepends the specified URI segment to all routes defined within the group.
Incorrect! Try again.
25How do you define an optional parameter in a route?
A.Route::get('/user/{id_opt}')
B.Route::get('/user/{id?}')
C.Route::get('/user/[id]')
D.Route::get('/user/*id')
Correct Answer: Route::get('/user/{id?}')
Explanation:
Placing a question mark ? after the parameter name makes it optional. You must usually provide a default value in the controller method.
Incorrect! Try again.
26Which feature allows you to restrict a group of routes to a specific subdomain?
A.Route::host('api.example.com')
B.Route::domain('api.example.com')
C.Route::subdomain('api')
D.Route::url('api.example.com')
Correct Answer: Route::domain('api.example.com')
Explanation:
The domain method allows you to group routes that should only handle requests for a specific domain or subdomain.
Incorrect! Try again.
27What helper function returns the full URL of the current request?
A.url()->now()
B.Route::current()
C.url()->current()
D.current_url()
Correct Answer: url()->current()
Explanation:
url()->current() (or URL::current()) returns the current URL without the query string.
Incorrect! Try again.
28How do you generate a URL to a specific application route named 'profile'?
A.link('profile')
B.href('profile')
C.route('profile')
D.url('profile')
Correct Answer: route('profile')
Explanation:
The route() helper generates a fully qualified URL to a named route.
Incorrect! Try again.
29When generating a URL to a named route that requires parameters, how are they passed?
A.route('profile?id=1')
B.route('profile', ['id' => 1])
C.route('profile', $id)
D.route('profile')->with('id', 1)
Correct Answer: route('profile', ['id' => 1])
Explanation:
The route function accepts an associative array as the second argument, where keys map to the route parameters.
Incorrect! Try again.
30Which helper function is used to generate a URL for a file located in the public directory (like CSS or images)?
A.public()
B.file()
C.asset()
D.resource()
Correct Answer: asset()
Explanation:
The asset() helper generates a URL for an asset using the current scheme of the request (HTTP or HTTPS).
Incorrect! Try again.
31What is the purpose of Route::fallback()?
A.To redirect to the home page on error.
B.To handle database connection failures.
C.To define a route that is executed when no other route matches the incoming request.
D.To provide a backup controller for heavy loads.
Correct Answer: To define a route that is executed when no other route matches the incoming request.
Explanation:
Fallback routes are used to handle 404 errors or situations where no other defined route matches the request URI.
Incorrect! Try again.
32To force a generated URL to use HTTPS, which helper function can be used?
A.url()->secure()
B.secure_url()
C.https_url()
D.ssl_route()
Correct Answer: secure_url()
Explanation:
The secure_url helper generates a fully qualified URL to the given path using the HTTPS protocol.
Incorrect! Try again.
33Which HTTP verb spoofing field is required in HTML forms to perform PUT or DELETE requests?
A._token
B._method
C._action
D._verb
Correct Answer: _method
Explanation:
Since HTML forms only support GET and POST, a hidden field named _method (containing PUT, DELETE, etc.) tells the framework to treat the request as that method.
Incorrect! Try again.
34What does the shortcut Route::view('/welcome', 'pages.welcome'); do?
A.It creates a controller that returns a view.
B.It redirects /welcome to pages.welcome.
C.It directly returns the view pages.welcome when /welcome is visited, without needing a dedicated controller.
D.It creates a view file.
Correct Answer: It directly returns the view pages.welcome when /welcome is visited, without needing a dedicated controller.
Explanation:
Route::view is a shortcut for defining a route that only returns a view.
Incorrect! Try again.
35What is the result of url()->previous()?
A.The URL of the home page.
B.The URL the user was at before the current request.
C.The parent directory of the current URL.
D.NULL if the user is not logged in.
Correct Answer: The URL the user was at before the current request.
Explanation:
It returns the referer URL, commonly used for 'Back' functionality.
Incorrect! Try again.
36Which directive can be used in Blade to check if the user is authenticated?
A.@check
B.@user
C.@auth
D.@if(logged_in)
Correct Answer: @auth
Explanation:
The @auth and @endauth directives are used to determine if the current user is authenticated.
Incorrect! Try again.
37In a Resource Controller, which method corresponds to the PUT/PATCH HTTP verb?
A.edit
B.save
C.update
D.store
Correct Answer: update
Explanation:
The update method is used to handle PUT or PATCH requests to modify an existing resource.
Incorrect! Try again.
38What is Route Model Binding?
A.Creating routes directly inside Model classes.
B.Automatically injecting model instances into routes based on parameter IDs.
C.Restricting routes to specific models.
D.Binding a route to a specific database table manually.
Correct Answer: Automatically injecting model instances into routes based on parameter IDs.
Explanation:
Route model binding provides a convenient way to automatically inject the model instance that matches the given ID in the route URI.
Incorrect! Try again.
39If you want to define a route that redirects to another URI, which shortcut is most efficient?
48Which parameter constraint regex matches any alphanumeric character?
A.\w
B.[a-zA-Z0-9]+
C.[0-9]+
D.[a-z]+
Correct Answer: [a-zA-Z0-9]+
Explanation:
Alphanumeric characters include letters (both cases) and numbers. Laravel also provides whereAlphaNumeric helper.
Incorrect! Try again.
49In a Resource Controller, which method corresponds to the POST HTTP verb for creating a new item?
A.store
B.create
C.make
D.insert
Correct Answer: store
Explanation:
The create method displays the form, but the store method handles the POST request to actually save the new resource.
Incorrect! Try again.
50What is the purpose of the Blade @stack directive?
A.To stack elements vertically in CSS.
B.To create a database transaction stack.
C.To render content pushed to a named stack from other views.
D.To debug the call stack.
Correct Answer: To render content pushed to a named stack from other views.
Explanation:
@stack('scripts') renders content that was added using @push('scripts') or @prepend('scripts') in child views.
Incorrect! Try again.
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 →