Font size
WorksheetsLaravel final
Total questions: 47
Worksheet time: 24mins
Which command in Laravel is used to create a new database migration?
php artisan make:database
php artisan create:migration
php artisan make:migration
php artisan generate:migration
Which of the following methods is used to define a foreign key constraint in a Laravel migration file?
index
references
primary
foreignId
Which of the following methods is used to define a default value for a column in a Laravel migration file?
nullable
default
inique
primary
Which of the following is a recommended way to retrieve a single record from a database table using Eloquent models?
findOrFail
find
first
paginate
Which of the following methods is used to drop a table in a Laravel migration file?
dropTable
removeTable
deleteTable
dropIfExists
Which of the following methods is used to define a pivot table for a many-to-many relationship in Laravel?
hasMany
belongsToMany
hasOne
belongsTo
Which of the following is a valid way to define a relationship between two Eloquent models in Laravel?
Using the hasMany method
Using the hasOne method
Using the bolongsTo method
All of these
Which of the following is a recommended way to update a record in a database table using Eloquent models?
Using the update method
Using the delete method
Using the save method
Using the destroy method
Which method is used to log out a user in Laravel?
logout()
signOut()
removeUser()
exit()
What does the Auth::guard() method allow you to do in Laravel authentication?
Create a new user
Retrieve the current user
Specify and use different authentication guards
Verify user credentials
What is the purpose of the Auth::user() method in Laravel?
Authenticates the current user
Logs out the user
Checks if the user is authorized
Retrieves the current authenticated user
In Laravel, which method is used to log in a user programmatically?
authenticate()
signIn()
login()
attempt()
Which configuration file in Laravel is used to define authentication settings?
config/auth.php
config/users.php
config/authenticate.php
config/security.php
What is the primary purpose of Authentication in Laravel?
Handling database operations
Routing configuration
Managing frontend assets
Verifying and identifying users
Which method in Laravel is used to redirect users after successful authentication?
redirectToAuthenticated()
redirectTo()
redirectAfterAuth()
redirect()
Which Laravel middleware is commonly used for authenticating user access to protected routes?
Protect
Verify
Authenticate
Authorize
In Laravel's authentication, what does the remember me functionality do ?
Keeps the user session active indefinitely
Stores the user's login credentials in a cookie
Remembers the user's login status across sessions
Logs the user out after a specified period
What does the @if directive in Blade do?
Includes a partial view
Loops through data
Conditionally renders content
Extends a layout
Which directive is used in Blade to extend a layout ?
@include
@extends
@layout
@yield
Which Blade directive is used to conditionally include content?
@unless
@when
@if
@isset
Your team is discussing the use of Blade template inheritance in Laravel. What is the primary benefit of Blade template inheritance?
To directly manipulate database entries
To enhance server performance
To promote code reusability and consistency
To exclude HTML structure in views
What does the @section directive do in Blade templates?
To comment on a section of code
To define a new section in a layout
To extend a parent layout
To include a partial view
Your team wants to reuse specific UI components across multiple views. How can you achieve this using Blade components in Laravel?
By embedding HTML directly in views for component reuse
By avoiding Blade components for simpler view structures
Use Laravel Blade components to create reusable UI elements.
By ignoring component reuse for faster development
Which of the following is not a valid way to pass data from a controller to a view in Laravel?
$data = ['title' => 'About Us']; return view('about', $data);
return view('welcome')->with('name', $name);
return view('dashboard')->with(['users' => $users, 'posts' => $posts]);
return view('profile')->compact('user', 'posts');
Which of the following is not a valid method for loading a JavaScript file in a Laravel view?
{{ asset('js/app.js') }}
mix('js/app.js')
@import('js/app.js')
{{ HTML::script('js/app.js') }}
Which of the following is not a valid way to set a session variable in Laravel?
session()->put('key', 'value');
session(['key' => 'value']);
session('key', 'value');
$_SESSION['key'] = 'value';
Which of the following is not a valid way to define a middleware group in Laravel?
Route::middleware(['auth', 'admin'])->group(function () { });
Route::group(['middleware' => 'auth'], function () { });
Route::middleware('auth', 'admin')->group(function () { });
Route::middleware(['auth'])->middleware(['admin'])->group(function () { });
Which package in Laravel allows for the creation and management of API tokens?
Sanctum
Jetstream
Socialite
passport
What is the primary purpose of API Authentication in Laravel?
Managing database operations
Validating user access to API endpoints
Validating user access to API endpoints
Validating user access to API endpoints
What is the purpose of Laravel's personal access tokens in API authentication?
Authenticating users via email tokens
Authorizing users for personal account access
Granting users scoped access to API routes
Generating API keys for third-party applications
How can you implement authentication middleware for API routes in Laravel?
By embedding authentication checks within each route
By using Laravel's auth middleware for API routes
By excluding middleware for faster API responses
By avoiding middleware usage for simpler routing
Which method in Laravel is used to validate and sanitize user input for security purposes?
validate()
sanitize()
secure()
filtre()
Which method in Laravel Collections is used to chunk the collection into smaller parts?
divide()
segment()
split()
chunk()
In Laravel Collections, what method is used to transform each item in the collection?
filter()
map()
reduce()
transform()
In Laravel, which method is used to sort a collection based on a specified callback or attribute?
sort()
order()
orderBy()
arrrange()
Your team wants to limit access to specific routes based on user roles. How can you implement request authorization in Laravel?
By directly managing role-based access within the routes
By applying middleware to perform role-based checks
By excluding routes based on user roles
By ignoring request authorization
What is the purpose of the authorize() method in a Laravel Request class?
To validate the incoming request against defined rules
To check if the user is authorized to perform the request
To handle the request before validation
To define middleware for the request
Which method is used to retrieve input data from the request in a Laravel Request class?
$this->input()
$this->retrieve()
$this->get()
$this->all()->input('name')
What is the primary purpose of Pusher in a Laravel application?
Secure user authentication
Real-time event broadcasting
Managing database transactions
Generating API documentation
Which Laravel package is specifically designed for documenting and testing APIs?
Sanctum
Spatie Permissions
Swagger
Queues and Jobs
In Laravel, which package is recommended for handling authentication in SPAs and mobile applications?
Passport
Sanctum
Pusher
WebSockets
What does Spatie Permissions provide in Laravel?
Managing authentication for API tokens
Handling event broadcasting
Role and permission management
API request validation
Which Laravel feature is primarily used for defining authorization logic?
Middleware
Policies
Sanctum
Queues
Which Laravel service is commonly used for integrating online payment processing?
WebSockets
Stripe Payment
Mollie Payment
Passport
What is the primary purpose of Queues and Jobs in Laravel?
Running background tasks asynchronously
Managing user authentication
Handling API request validation
Managing database migrations
Which Laravel feature allows developers to schedule repetitive tasks to run at specified intervals?
Policies
Middleware
Schedule
Broadcasting
What is the primary difference between Pusher and WebSockets in Laravel?
Pusher is a third-party service, while Laravel WebSockets provides a self-hosted solution
WebSockets only works with Laravel, while Pusher works with any framework
Pusher does not support real-time events
WebSockets is only used for authentication
