Unit 3 - Practice Quiz

INT221 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 Which Artisan command is used to generate a basic controller class in a Laravel/MVC environment?

A. php artisan new:controller UserController
B. php artisan make:controller UserController
C. php artisan create:controller UserController
D. php artisan generate:controller UserController

2 In a controller method, what is the primary mechanism for accessing data submitted via an HTTP POST request?

A. Reading from php://input
B. Using the $_POST superglobal directly
C. Type-hinting the Illuminate\Http\Request class
D. Using the Input::get() facade only

3 Which method is automatically called when a controller is instantiated, often used to register middleware?

A. __construct()
B. boot()
C. init()
D. register()

4 What is a Single Action Controller?

A. A controller that can only handle GET requests
B. A controller that does not extend the base Controller class
C. A controller containing only an __invoke method
D. A controller that cannot use middleware

5 When generating a Resource Controller, which flag is added to the artisan command?

A. --restful
B. --resource
C. --crud
D. --all

6 Which of the following methods is NOT included in an API Resource Controller (generated with --api)?

A. store
B. index
C. destroy
D. edit

7 Which routing statement creates routes for all seven standard resource actions at once?

A. Route::crud('photos', PhotoController::class);
B. Route::resource('photos', PhotoController::class);
C. Route::all('photos', PhotoController::class);
D. Route::controller('photos', PhotoController::class);

8 In the context of Controller Routing, what does the syntax [UserController::class, 'show'] represent?

A. An array of middleware to apply
B. A route group definition
C. The controller class and the specific method to execute
D. A resource definition

9 What file extension is strictly required for Blade templates?

A. .blade
B. .php
C. .blade.php
D. .tpl.php

10 Which Blade syntax is used to echo data while automatically escaping special characters to prevent XSS attacks?

A. @echo($data)
B. {{ $data }}
C. <?= $data ?>
D. {!! $data !!}

11 If you need to display unescaped HTML data in Blade, which syntax should be used?

A. {!! $data !!}
B. @raw($data)
C. {{ $data }}
D. {{-- $data --}}

12 Which directive is used to define a placeholder in a layout file that child views can inject content into?

A. @yield
B. @section
C. @include
D. @extends

13 Which directive is used at the beginning of a child view to specify which layout it inherits from?

A. @layout
B. @template
C. @extends
D. @parent

14 What 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 /

15 Inside a @foreach loop in Blade, what special variable is automatically available to check the current iteration state?

A. $iterator
B. $loop
C. $index
D. $foreach

16 Which Blade directive functions as the inverse of @if (executes if the condition is false)?

A. @ifnot
B. @else
C. @unless
D. @empty

17 How do you include a sub-view partials/header.blade.php inside another view?

A. @require('partials.header')
B. @include('partials.header')
C. @import('partials.header')
D. @yield('partials.header')

18 Which directive allows you to define a block of JavaScript that will remain untouched by the Blade engine (useful for JS frameworks)?

A. @javascript
B. @literal
C. @raw
D. @verbatim

19 When defining content for a section, what directive is used to append content to the parent's section rather than overwriting it?

A. @base
B. @super
C. @parent
D. @append

20 What is the primary benefit of using Named Routes?

A. They automatically apply security headers.
B. They are processed faster by the server.
C. They allow URL generation independent of the actual URI path.
D. They make the URL shorter.

21 How do you assign a name to a route definition?

A. Route::get('/path')->name('name');
B. Route::get('/path')->label('name');
C. Route::get('/path')->as('name');
D. Route::get('/path', ['name' => 'name']);

22 What is the correct syntax to define a route parameter constraint ensuring the id is numeric?

A. Route::get('/user/{id}')->where('id', '[0-9]+');
B. Route::get('/user/{id}')->constraint('id', 'int');
C. Route::get('/user/{id}')->expect('id', '\d+');
D. Route::get('/user/{id}')->validate('id', 'numeric');

23 Which method is used to define a group of routes that share common attributes like middleware or prefixes?

A. Route::group(...)
B. Route::bundle(...)
C. Route::collection(...)
D. Route::batch(...)

24 Consider the code: Route::prefix('admin')->group(...). If a route inside the group is /dashboard, what is the resulting URL?

A. /admin-dashboard
B. /dashboard
C. /dashboard/admin
D. /admin/dashboard

25 How 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?}')

26 Which feature allows you to restrict a group of routes to a specific subdomain?

A. Route::subdomain('api')
B. Route::host('api.example.com')
C. Route::domain('api.example.com')
D. Route::url('api.example.com')

27 What helper function returns the full URL of the current request?

A. url()->current()
B. url()->now()
C. current_url()
D. Route::current()

28 How do you generate a URL to a specific application route named 'profile'?

A. url('profile')
B. link('profile')
C. route('profile')
D. href('profile')

29 When generating a URL to a named route that requires parameters, how are they passed?

A. route('profile', ['id' => 1])
B. route('profile')->with('id', 1)
C. route('profile', $id)
D. route('profile?id=1')

30 Which helper function is used to generate a URL for a file located in the public directory (like CSS or images)?

A. asset()
B. public()
C. file()
D. resource()

31 What is the purpose of Route::fallback()?

A. To redirect to the home page on error.
B. To provide a backup controller for heavy loads.
C. To handle database connection failures.
D. To define a route that is executed when no other route matches the incoming request.

32 To force a generated URL to use HTTPS, which helper function can be used?

A. https_url()
B. ssl_route()
C. secure_url()
D. url()->secure()

33 Which HTTP verb spoofing field is required in HTML forms to perform PUT or DELETE requests?

A. _action
B. _token
C. _method
D. _verb

34 What does the shortcut Route::view('/welcome', 'pages.welcome'); do?

A. It redirects /welcome to pages.welcome.
B. It creates a controller that returns a view.
C. It directly returns the view pages.welcome when /welcome is visited, without needing a dedicated controller.
D. It creates a view file.

35 What 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.

36 Which directive can be used in Blade to check if the user is authenticated?

A. @if(logged_in)
B. @check
C. @auth
D. @user

37 In a Resource Controller, which method corresponds to the PUT/PATCH HTTP verb?

A. store
B. edit
C. save
D. update

38 What is Route Model Binding?

A. Restricting routes to specific models.
B. Automatically injecting model instances into routes based on parameter IDs.
C. Binding a route to a specific database table manually.
D. Creating routes directly inside Model classes.

39 If you want to define a route that redirects to another URI, which shortcut is most efficient?

A. Route::get('/here', function() { return redirect('/there'); });
B. Route::redirect('/here', '/there');
C. Route::forward('/here', '/there');
D. Route::move('/here', '/there');

40 In Blade, how can you output a variable as JSON, useful for passing data to JavaScript?

A. {{ json_encode($data) }}
B. {{ $data->toJson() }}
C. @json($data)
D. @js($data)

41 What is the purpose of the action() helper?

A. To generate a URL to a given controller action.
B. To validate a request action.
C. To perform a controller action immediately.
D. To create a form action attribute.

42 When using Route::group(['middleware' => ['auth']], ...) what happens?

A. The middleware is ignored.
B. It defines a middleware controller.
C. The auth middleware is applied to all routes defined within the group.
D. The routes in the group are public.

43 Which Blade control structure is used to check if a collection is empty before iterating?

A. @switch ... @case ... @endswitch
B. @forelse ... @empty ... @endforelse
C. @while ... @empty ... @endwhile
D. @foreach ... @else ... @endforeach

44 In a Controller, what does the helper view('home', ['name' => 'John']) do?

A. Compiles the 'home' view and passes the variable $name with value 'John' to it.
B. Returns a JSON response.
C. Redirects to the home route.
D. Creates a new view file named home.

45 How do you define a global pattern constraint for route parameters (e.g., ensuring id is always numeric across all routes)?

A. In the .env file
B. In the web.php file using Route::global()
C. In the Controller's constructor
D. In the RouteServiceProvider's boot method using Route::pattern()

46 Which syntax is used to stop the execution of a Blade @php block?

A. @endphp
B. @stop
C. @done
D. @end

47 If you have a named route photos.index which points to /photos, what does route('photos.index') return?

A. The string '/photos'
B. The controller method
C. The view file path

48 Which parameter constraint regex matches any alphanumeric character?

A. [a-zA-Z0-9]+
B. [0-9]+
C. \w
D. [a-z]+

49 In a Resource Controller, which method corresponds to the POST HTTP verb for creating a new item?

A. make
B. store
C. insert
D. create

50 What is the purpose of the Blade @stack directive?

A. To stack elements vertically in CSS.
B. To debug the call stack.
C. To render content pushed to a named stack from other views.
D. To create a database transaction stack.