Eloquent as a Middleware

Hi there,

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

Thanks.

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…

1 Like

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