I. Answer with True or False
2.1)-
Controllers must always extend the base Controller class to function in Laravel. (11 pt)
True
False
2.2)-
Dependency injection can be used in a controller constructor to automatically resolve classes from the service container. (8 pt)
True
False
2.3)-
The "php artisan make:controller" command creates a controller in the App/Http/Controllers directory by default. (3 pt)
True
False
2.4)-
A Single Action Controller is defined by using the __invoke() magic method. (6 pt)
True
False
2.5)-
Laravel routes are defined in web.php (3 pt)
True
False
2.6)-
Route groups allow you to share attributes, such as middleware or namespaces, across a large number of routes. (6 pt)
True
False
2.7)-
Laravel routes defined in web.php are automatically assigned the "api" middleware group. (3 pt)
True
False
2.8)-
The Route::resource method automatically generates a route for a "patch" request. (6 pt)
True
False
II. Pick the correct answer from the given options
3.1)-
In a Resource controller, which method is used to display a specific record? (3 pt)
(a) show()
(b) view()
(c) find()
(d) display()
3.2)-
Which Artisan command is used to create a controller with CRUD methods? (3 pt)
(a) make:controller --all
(b) make:controller --resource
(c) make:controller --crud
(d) make:controller --api
3.3)-
How can you exclude the "show" method from a Resource Controller? (6 pt)
(a) ->only(["show"])
(b) ->hide(["show"])
(c) ->remove(["show"])
(d) ->except(["show"])
3.4)-
What is the purpose of the "constructor" in a controller? (8 pt)
(a) Dependency injection and shared logic
(b) Defining the routes
(c) Rendering the view directly
(d) Handling database migrations
3.5)-
Which method is typically used to process data from a "Create" form? (3 pt)
(a) index()
(b) store()
(c) update()
(d) patch()
3.6)-
Which route method is used to respond to a form submitted via PUT? (6 pt)
(a) Route::update()
(b) Route::set()
(c) Route::patch()
(d) Route::put()
3.7)-
How can you apply a middleware to a group of routes? (6 pt)
(a) Route::secure()
(b) Route::wrap()
(c) Route::middleware()
(d) Route::filter()
3.8)-
Where are the web-specific routes defined in a default Laravel installation? (3 pt)
(a) api.php
(b) console.php
(c) channels.php
(d) web.php
3.9)-
Which helper function is used to generate a URL for a named route? (3 pt)
(a) link()
(b) route()
(c) url_path()
(d) named()
3.10)-
Which method is used to redirect one URI to another? (3 pt)
(a) Route::redirect()
(b) Route::to()
(c) Route::move()
(d) Route::send()
3.11)-
What is the purpose of the "fallback" route? (8 pt)
(a) To handle 404 errors when no other route matches
(b) To redirect all traffic to the homepage
(c) To cache the route list
(d) To define API-only endpoints
3.12)-
How do you define a route that responds to all HTTP verbs? (6 pt)
(a) Route::all()
(b) Route::global()
(c) Route::any()
(d) Route::every()