Test yourself under real exam conditions: 50 timed questions, 60 on the clock, pass mark 70%%. Instant score with a full review of everything you got wrong. Free — no account needed.
Exam details
Eloquent is Laravel's built-in Active Record ORM. Each database table has a corresponding Model class used to interact with that table. It provides an expressive syntax for queries:$users = User::where('active', true)->get();
In the parent model, define a method returning hasMany():public function posts() { return $this->hasMany(Post::class); }
In the child model, define the inverse with belongsTo():public function user() { return $this->belongsTo(User::class); }
Eager loading solves the N+1 query problem by loading relationships upfront:$books = Book::with('author')->get();
Without it, accessing a relationship in a loop triggers a separate query per iteration, causing performance issues.
Use the Artisan command:php artisan make:model Post -m
The -m flag generates a migration file alongside the model. You can also add -f for a factory and -s for a seeder.
Accessors transform attribute values when reading:protected function firstName(): Attribute { return Attribute::make(get: fn($value) => ucfirst($value)); }
Mutators transform values when setting:set: fn($value) => strtolower($value)