Home > PHP Laravel MCQ Questions and Answers > Laravel Eloquent ORM

Laravel Eloquent ORM

1
What is Eloquent in Laravel?
A templating engine
An ORM (Object-Relational Mapping) library
A routing system
A testing framework
2
How do you define a model in Laravel?
By creating a class that extends the Model class
By creating a database migration
By creating a controller
By defining a route
3
What naming convention does Eloquent use for model names?
All lowercase with underscores
Singular and PascalCase
All uppercase
All lowercase with hyphens
4
What are timestamps in Eloquent models?
They record the time a record is accessed
They are used to track record creation and update times
They are used for logging purposes
They determine the database connection time
5
How can you disable timestamps in an Eloquent model?
By setting the $timestamps property to false
By removing the timestamp columns from the database
By changing the model's name
By defining the timestamps in the constructor
6
Which of the following methods is used to insert a new record using Eloquent?
save()
create()
insert()
add()
7
How do you retrieve all records from a model in Eloquent?
Model::getAll()
Model::fetch()
Model::all()
Model::findAll()
8
What method is used to delete a record in Eloquent?
delete()
remove()
erase()
discard()
9
How can you filter records in Eloquent?
Using the where() method
Using the filter() method
Using the select() method
Using the query() method
10
How do you retrieve a single record or throw an exception if not found?
findOrFail()
getOrFail()
fetchOrFail()
retrieveOrFail()
11
Which method is used to retrieve records with pagination in Eloquent?
paginate()
limit()
take()
getWithLimit()
12
What is the purpose of the with() method in Eloquent?
To fetch related models
To apply conditions on queries
To order results
To group results
13
Which Eloquent method is used to count the number of records?
total()
count()
tally()
sum()
14
How do you prevent mass assignment vulnerabilities in Laravel models?
By setting the $fillable property
By using the $guarded property
By defining a constructor
By using the validate() method
15
How can you retrieve unique records from a model?
unique()
distinct()
uniqueRecords()
distinctRecords()