ORM and SlimFramework

Hi. I have a project api on Slim. I am using SQL to save/fetch/delete/update date in MySql database. However it takes time an much space in bigger project to use and manage this.

Now I am thinking to move to some ORM like Eloquent.

  • Is this better than SQL?
  • Which ORM is the best and comfortable?

Thanks!

Those questions are likely to yield many different opinions. I’d say if you can ultimately develop projects faster with fewer bugs, then it is worth it. The trade-offs might include speed, memory, and testability.

Likewise there are many different opinions about the “best” ORM. After checking out a few including Eloquent, Fuel, RedBean, and Propel, I ended up using Eloquent as it was the most intuitive to me and it had the most tutorials.

Yes Eloquent is easy to start. But the experience with Eloquent was better than traditional SQL queries?

For me it is. Being able to just write $user->save(); or $user->update(); is easier than writing all of the queries. Likewise for relationships doing something like $invoices = $user->invoices(); is easier for me than writing the join.

Relationships is really cool. Thanks!

There are many great tutorial videos about Eloquent at Laracasts. I believe the Eloquent 101 episode is free, to get you started to see what it can do. It is based on Laravel, not Slim, but using Eloquent would be much the same.

Thanks! Do you know some other video lessons?

There are probably a couple dozen lessons on Eloquent at Laracasts which are fantastic. Codecourse has a lesson specifically on using Eloquent with Slim as well as a few other lessons on Eloquent.

The amazing @akrabat has a example project using Slim and Eloquent, and the official Slim Docs have a cookbook entry for Using Eloquent with Slim.

1 Like

@AndersonDev probably the most powerful, but definitely not the easiest to learn is doctrine http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/.

There are Pimple related Services providers which work with Slim3:
http://silex.sensiolabs.org/doc/master/providers/doctrine.html (dbal)
https://github.com/dflydev/dflydev-doctrine-orm-service-provider (orm)

Regards Dominik

Doctrine is really the most powerful PHP ORM, but for me not so easy to understand and work with. Eloquent is simple and elegant)

For something lighter weight, I like paris/idiorm - though with php7 / slim 3 the voku/paris fork is working great for me.

I have not seen benchmarks, but I suspect it is faster than Eloquent or Docterine, though has fewer features.