Laravel Database
1
What is the purpose of a query builder in Laravel?
To create database migrations
To construct SQL queries programmatically
To seed the database
To backup the database
2
Which method is used to retrieves all records from a table using Laravel's Query Builder?
get()
all()
select()
fetch()
3
What does the
first() method do in Laravel's Query Builder?
Returns all results
Returns the first result of a query
Returns the last result of a query
Returns a random result
4
Which method can be used to perform a JOIN operation in Laravel's Query Builder?
join()
link()
connect()
combine()
5
What is a migration in Laravel?
A method to migrate data from one server to another
A version control system for your database
A way to automate backups of your database
A process to encrypt database fields
6
Which command is used to create a new migration in Laravel?
php artisan migrate
php artisan make:migration
php artisan migrate:migration
php artisan create:migration
7
What is seeding in the context of a database?
Filling a database with initial data
Deleting records from a database
Updating existing records
Creating database backups
8
Which method is used to run the seeders in Laravel?
php artisan seed
php artisan db:seed
php artisan migrate
php artisan run
9
What is the purpose of the
database/factories directory in Laravel?
To store database migration files
To define model factories for generating test data
To manage database connections
To handle database migrations
10
Which of the following methods can be used to perform a soft delete in Laravel?
delete()
remove()
softDelete()
forceDelete()
11
What does the
fillable property in a model define?
Fields that can be validated
Fields that can be mass assigned
Fields that can be deleted
Fields that are required
12
How do you update existing records in a database using Laravel's Query Builder?
update()
edit()
modify()
change()
13
How can you create a foreign key in a Laravel migration?
foreignKey('column_name')
references('column_name')
foreign('column_name')->references('id')->on('other_table')
linkTo('other_table')
14
What happens when you run
php artisan migrate:fresh?
It rolls back all migrations
It drops all tables and runs all migrations
It refreshes only the specified migration
It generates a new migration file