wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Laravel final

Total questions: 47

Worksheet time: 24mins

Name
Class
Date
1.

Which command in Laravel is used to create a new database migration?

a)

php artisan make:database

b)

php artisan create:migration

c)

php artisan make:migration

d)

php artisan generate:migration

2.

Which of the following methods is used to define a foreign key constraint in a Laravel migration file?

a)

index

b)

references

c)

primary

d)

foreignId

3.

Which of the following methods is used to define a default value for a column in a Laravel migration file?

a)

nullable

b)

default

c)

inique

d)

primary

4.

Which of the following is a recommended way to retrieve a single record from a database table using Eloquent models?

a)

findOrFail

b)

find

c)

first

d)

paginate

5.

Which of the following methods is used to drop a table in a Laravel migration file?

a)

dropTable

b)

removeTable

c)

deleteTable

d)

dropIfExists

6.

Which of the following methods is used to define a pivot table for a many-to-many relationship in Laravel?

a)

hasMany

b)

belongsToMany

c)

hasOne

d)

belongsTo

7.

Which of the following is a valid way to define a relationship between two Eloquent models in Laravel?

a)

Using the hasMany method

b)

Using the hasOne method

c)

Using the bolongsTo method

d)

All of these

8.

Which of the following is a recommended way to update a record in a database table using Eloquent models?

a)

Using the update method

b)

Using the delete method

c)

Using the save method

d)

Using the destroy method

9.

Which method is used to log out a user in Laravel?

a)

logout()

b)

signOut()

c)

removeUser()

d)

exit()

10.

What does the Auth::guard() method allow you to do in Laravel authentication?

a)

Create a new user

b)

Retrieve the current user

c)

Specify and use different authentication guards

d)

Verify user credentials

11.

What is the purpose of the Auth::user() method in Laravel?

a)

Authenticates the current user

b)

Logs out the user

c)

Checks if the user is authorized

d)

Retrieves the current authenticated user

12.

In Laravel, which method is used to log in a user programmatically?

a)

authenticate()

b)

signIn()

c)

login()

d)

attempt()

13.

Which configuration file in Laravel is used to define authentication settings?

a)

config/auth.php

b)

config/users.php

c)

config/authenticate.php

d)

config/security.php

14.

What is the primary purpose of Authentication in Laravel?

a)

Handling database operations

b)

Routing configuration

c)

Managing frontend assets

d)

Verifying and identifying users

15.

Which method in Laravel is used to redirect users after successful authentication?

a)

redirectToAuthenticated()

b)

redirectTo()

c)

redirectAfterAuth()

d)

redirect()

16.

Which Laravel middleware is commonly used for authenticating user access to protected routes?

a)

Protect

b)

Verify

c)

Authenticate

d)

Authorize

17.

In Laravel's authentication, what does the remember me functionality do ?

a)

Keeps the user session active indefinitely

b)

Stores the user's login credentials in a cookie

c)

Remembers the user's login status across sessions

d)

Logs the user out after a specified period

18.

What does the @if directive in Blade do?

a)

Includes a partial view

b)

Loops through data

c)

Conditionally renders content

d)

Extends a layout

19.

Which directive is used in Blade to extend a layout ?

a)

@include

b)

@extends

c)

@layout

d)

@yield

20.

Which Blade directive is used to conditionally include content?

a)

@unless

b)

@when

c)

@if

d)

@isset

21.

Your team is discussing the use of Blade template inheritance in Laravel. What is the primary benefit of Blade template inheritance?

a)

To directly manipulate database entries

b)

To enhance server performance

c)

To promote code reusability and consistency

d)

To exclude HTML structure in views

22.

What does the @section directive do in Blade templates?

a)

To comment on a section of code

b)

To define a new section in a layout

c)

To extend a parent layout

d)

To include a partial view

23.

Your team wants to reuse specific UI components across multiple views. How can you achieve this using Blade components in Laravel?

a)

By embedding HTML directly in views for component reuse

b)

By avoiding Blade components for simpler view structures

c)

Use Laravel Blade components to create reusable UI elements.

d)

By ignoring component reuse for faster development

24.

Which of the following is not a valid way to pass data from a controller to a view in Laravel?

a)

$data = ['title' => 'About Us']; return view('about', $data);

b)

return view('welcome')->with('name', $name);

c)

return view('dashboard')->with(['users' => $users, 'posts' => $posts]);

d)

return view('profile')->compact('user', 'posts');

25.

Which of the following is not a valid method for loading a JavaScript file in a Laravel view?

a)

{{ asset('js/app.js') }}

b)

mix('js/app.js')

c)

@import('js/app.js')

d)

{{ HTML::script('js/app.js') }}

26.

Which of the following is not a valid way to set a session variable in Laravel?

a)

session()->put('key', 'value');

b)

session(['key' => 'value']);

c)

session('key', 'value');

d)

$_SESSION['key'] = 'value';

27.

Which of the following is not a valid way to define a middleware group in Laravel?

a)

Route::middleware(['auth', 'admin'])->group(function () { });

b)

Route::group(['middleware' => 'auth'], function () { });

c)

Route::middleware('auth', 'admin')->group(function () { });

d)

Route::middleware(['auth'])->middleware(['admin'])->group(function () { });

28.

Which package in Laravel allows for the creation and management of API tokens?

a)

Sanctum

b)

Jetstream

c)

Socialite

d)

passport

29.

What is the primary purpose of API Authentication in Laravel?

a)

Managing database operations

b)

Validating user access to API endpoints

c)

Validating user access to API endpoints

d)

Validating user access to API endpoints

30.

What is the purpose of Laravel's personal access tokens in API authentication?

a)

Authenticating users via email tokens

b)

Authorizing users for personal account access

c)

Granting users scoped access to API routes

d)

Generating API keys for third-party applications

31.

How can you implement authentication middleware for API routes in Laravel?

a)

By embedding authentication checks within each route

b)

By using Laravel's auth middleware for API routes

c)

By excluding middleware for faster API responses

d)

By avoiding middleware usage for simpler routing

32.


Which method in Laravel is used to validate and sanitize user input for security purposes?

a)

validate()

b)

sanitize()

c)

secure()

d)

filtre()

33.

Which method in Laravel Collections is used to chunk the collection into smaller parts?

a)

divide()

b)

segment()

c)

split()

d)

chunk()

34.

In Laravel Collections, what method is used to transform each item in the collection?

a)

filter()

b)

map()

c)

reduce()

d)

transform()

35.

In Laravel, which method is used to sort a collection based on a specified callback or attribute?

a)

sort()

b)

order()

c)

orderBy()

d)

arrrange()

36.

Your team wants to limit access to specific routes based on user roles. How can you implement request authorization in Laravel?

a)

By directly managing role-based access within the routes

b)

By applying middleware to perform role-based checks

c)

By excluding routes based on user roles

d)

By ignoring request authorization

37.

What is the purpose of the authorize() method in a Laravel Request class?

a)

To validate the incoming request against defined rules

b)

To check if the user is authorized to perform the request

c)

To handle the request before validation

d)

To define middleware for the request

38.

Which method is used to retrieve input data from the request in a Laravel Request class?

a)

$this->input()

b)

$this->retrieve()

c)

$this->get()

d)

$this->all()->input('name')

39.

What is the primary purpose of Pusher in a Laravel application?

a)

Secure user authentication

b)

Real-time event broadcasting

c)

Managing database transactions

d)

Generating API documentation

40.

Which Laravel package is specifically designed for documenting and testing APIs?

a)

Sanctum

b)

Spatie Permissions

c)

Swagger

d)

Queues and Jobs

41.

In Laravel, which package is recommended for handling authentication in SPAs and mobile applications?

a)

Passport

b)

Sanctum

c)

Pusher

d)

WebSockets

42.

What does Spatie Permissions provide in Laravel?

a)

Managing authentication for API tokens

b)

Handling event broadcasting

c)

Role and permission management

d)

API request validation

43.

Which Laravel feature is primarily used for defining authorization logic?

a)

Middleware

b)

Policies

c)

Sanctum

d)

Queues

44.

Which Laravel service is commonly used for integrating online payment processing?

a)

WebSockets

b)

Stripe Payment

c)

Mollie Payment

d)

Passport

45.

What is the primary purpose of Queues and Jobs in Laravel?

a)

Running background tasks asynchronously

b)

Managing user authentication

c)

Handling API request validation

d)

Managing database migrations

46.

Which Laravel feature allows developers to schedule repetitive tasks to run at specified intervals?

a)

Policies

b)

Middleware

c)

Schedule

d)

Broadcasting

47.

What is the primary difference between Pusher and WebSockets in Laravel?

a)

Pusher is a third-party service, while Laravel WebSockets provides a self-hosted solution

b)

WebSockets only works with Laravel, while Pusher works with any framework

c)

Pusher does not support real-time events

d)

WebSockets is only used for authentication