LARAVEL Eloquent ORM & Database Flashcards
6 cards from real LARAVEL practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 6 LARAVEL Eloquent ORM & Database flashcards as text
What does the `DB::transaction()` method ensure in Laravel?
Answer: That all contained database operations either fully commit or fully roll back on failure
DB::transaction() wraps multiple queries in a database transaction, guaranteeing atomicity so partial failures trigger a full rollback.
Which Eloquent relationship method is used on a child model to reference its parent?
Answer: belongsTo()
belongsTo() declares the inverse of a one-to-one or one-to-many relationship, pointing from the child model to its parent.
What is the function of a database seeder in Laravel?
Answer: To populate the database with sample or test data
Seeders are PHP classes that insert predefined sample data into database tables, useful for testing and development environments.
Which method chains onto an Eloquent query to add a WHERE clause filtering by column equality?
Answer: ->where('column', 'value')
The where() method adds a basic SQL WHERE condition to the Eloquent query builder, accepting a column name and comparison value.
What does `Model::factory()` provide in Laravel?
Answer: A fluent interface for generating fake model instances for testing
Model factories use Faker to generate realistic fake data and create model instances for tests and database seeding.
What is the purpose of the `$casts` property in an Eloquent model?
Answer: To automatically convert attribute values to specified data types when reading or writing
The $casts property defines automatic type conversion for attributes, such as casting a JSON column to an array or an integer string to int.
How this page was made: written with AI tools and published by Nathan Beja, founder of Practice Test Geeks, who is responsible for its content. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Not reviewed by a subject-matter expert. Editorial policy