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 create:controller UserController
B. php artisan make:controller UserController
C. php artisan generate:controller UserController
D. php artisan new:controller UserController

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

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

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

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

4 What is a Single Action Controller?

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

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

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

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

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

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

A. Route::all('photos', PhotoController::class);
B. Route::resource('photos', PhotoController::class);
C. Route::crud('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. The controller class and the specific method to execute
C. A resource definition
D. A route group definition

9 What file extension is strictly required for Blade templates?

A. .php
B. .blade
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. {{ $data }}
B. {!! $data !!}
C. <?= $data ?>
D. @echo($data)

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

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

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

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

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

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

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. $index
C. $loop
D. $foreach

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

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

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

A. @require('partials.header')
B. @import('partials.header')
C. @include('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. @literal
B. @javascript
C. @verbatim
D. @raw

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

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

20 What 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 automatically apply security headers.
D. They are processed faster by the server.

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

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

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

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

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

A. Route::bundle(...)
B. Route::collection(...)
C. Route::group(...)
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. /dashboard/admin
B. /admin/dashboard
C. /dashboard
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::domain('api.example.com')
C. Route::host('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. route('profile')
C. link('profile')
D. href('profile')

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

A. route('profile', $id)
B. route('profile', ['id' => 1])
C. route('profile?id=1')
D. route('profile')->with('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. public()
B. resource()
C. asset()
D. file()

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

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

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

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

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

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

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

A. It creates a controller that returns a view.
B. It directly returns the view pages.welcome when /welcome is visited, without needing a dedicated controller.
C. It redirects /welcome to pages.welcome.
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. @auth
C. @check
D. @user

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

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

38 What is Route Model Binding?

A. Binding a route to a specific database table manually.
B. Automatically injecting model instances into routes based on parameter IDs.
C. Restricting routes to specific models.
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::move('/here', '/there');
D. Route::forward('/here', '/there');

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

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

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

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

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

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

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

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

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

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

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 web.php file using Route::global()
B. In the RouteServiceProvider's boot method using Route::pattern()
C. In the Controller's constructor
D. In the .env file

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

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

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

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

48 Which parameter constraint regex matches any alphanumeric character?

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

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

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

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

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