Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 3 of 10 · Laravel Framework Fundamentals
Interview question

What is Eloquent ORM and how does it differ from raw SQL? Eloquent ORM क्या है और raw SQL से कैसे अलग है?

Answer

Eloquent is Laravel's ActiveRecord-style ORM. Each database table has a corresponding Model class used to interact with that table.

// Raw SQL
$users = DB::select('SELECT * FROM users WHERE active = 1');

// Eloquent
$users = User::where('active', 1)->get();

// Relationships in Eloquent
class Post extends Model {
    public function comments() {
        return $this->hasMany(Comment::class);
    }
}
$post->comments; // lazy-loaded collection
AspectRaw SQLEloquent
ReadabilityLower for complex joinsHigher, fluent chainable API
RelationshipsManual joinshasMany, belongsTo, etc.
Database portabilitySQL dialect-specificAbstracted across databases

Eloquent Laravel का ActiveRecord-style ORM है। हर database table का एक Model class होता है।

// Raw SQL
$users = DB::select('SELECT * FROM users WHERE active = 1');

// Eloquent
$users = User::where('active', 1)->get();

class Post extends Model {
    public function comments() {
        return $this->hasMany(Comment::class);
    }
}

Was this answer clear?