โ† All LARAVEL Flashcard Decks

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
  1. What class must a Laravel Eloquent model extend?

    Answer: Illuminate\Database\Eloquent\Model

    All Eloquent models must extend the base Illuminate\Database\Eloquent\Model class to gain ORM functionality.

  2. Which Eloquent method retrieves all records from a database table?

    Answer: Model::all()

    Model::all() returns an Eloquent Collection containing every record in the model's corresponding database table.

  3. What is the purpose of the `$fillable` property in an Eloquent model?

    Answer: To whitelist attributes that are mass-assignable

    The $fillable array guards against mass-assignment vulnerabilities by explicitly allowing only listed attributes to be set via create() or fill().

  4. Which Eloquent method finds a model by its primary key and throws an exception if not found?

    Answer: findOrFail()

    findOrFail() retrieves a model by primary key and throws a ModelNotFoundException if no record exists.

  5. How do you define a one-to-many relationship in Eloquent from the parent model?

    Answer: public function children() { return $this->hasMany(Child::class); }

    The hasMany() method defines a one-to-many relationship where the current model is the parent with multiple related records.

  6. What does eager loading with `with()` prevent in Laravel?

    Answer: The N+1 query problem

    Eager loading via with() loads related models in a fixed number of queries rather than issuing a new query for each parent record, solving the N+1 problem.

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