Eloquent as a Middleware


#1

Hi there,

Is it good idea to use Eloquent as a middleware? Or should I use it in DI container?

Thanks.


#2

Hi @Enindu

Eloquent is a (application) service, like the logger, mailer, template engine etc. All services should be created within the container factory (e.g. in dependencies.php)

Is it good idea to use Eloquent as a middleware?

No, because Eloquent is not http (request/response) related. Eloquent is not a middleware, it’s a application service.

Or should I use it in DI container?

You can (should) create the Eloquent instance within the DI container (factory), but use it within the domain service etc…


#3

Hi @odan,
I really appreciate the answer. That makes sense.