Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lxg's avatar
Level 1

Concrete advantages of the Eloquent ORM

Hello,

I have to tell my Boss what the advantages of the Eloquent ORM are. I am very new to ORM and Laravel and im very unexperienced with that yet. Can you tell me advantages or give me a link to a website or book that lists them.

Thank you very much in advance!

Best regards lxg

0 likes
4 replies
Tray2's avatar

The advantages is mostly nice looking code. For example

public function show($id)
{
    $book = Book::findOrFail($id);
    return view('books.show')->with('book', $book);
}

and

public function store(Request $request)
{
   $this->validateGenre($request);
   $genre = new Genre();
   $genre->genre = $request->genre;
   $genre->save();
}

To do the same thing in sql with the db facade would look something like

public function show($id)
{
    $book = Db:select('SELECT * FROM books WHERE id = ?', [$id]);
    return view('books.show')->with('book', $book);
}
public function store(Request $request)
{
   $this->validateGenre($request);
   DB::insert('INSERT INTO genre (id,  genre) values (?, ?)', [null, $request->genre]);
}
jlrdw's avatar

Eloquent makes some things easier but eloquent can not do it all.

It boils down to the right tool for the job or query in this case.

But remember anyting eloquent does is converted to normal SQL at runtime.

But remember even if you have a complex query that maybe eloquent won't handle you still have the DB facade in which you can write any query. And there's also getPdo (), which is the PDO instance.

Snapey's avatar

For me, its a case of writing code that reflects what I am trying to do in my application, not code that SQL requires.

Please or to participate in this conversation.