Knowledgebase

Using the Query Builder Print

  • phplaravel, guide, howto, solution, zillionkinghost, hosting, support
  • 0

When Eloquent is not the right tool.

WHEN TO USE IT

Complex aggregations Reports across several tables Bulk operations Anywhere model overhead is unnecessary

WHAT IT PROVIDES

A fluent way of constructing queries, with parameterisation.

WHAT IT DOES NOT PROVIDE

Model behaviour: casting, relationships, events.

WHAT THAT MEANS

Bulk operations through the builder bypass model events.

Be aware, where those matter.

WHAT TO USE FOR VERY LARGE UPDATES

The builder, which updates in one statement rather than record by record.

WHAT TO BE CAREFUL WITH

Raw expressions, which are not parameterised automatically Dynamic column names from input

WHAT TO DO ABOUT RAW EXPRESSIONS

Bind values explicitly.

Never interpolate.

WHAT TO PREFER

The builder over raw SQL, and Eloquent over the builder, unless there is a reason.

WHY THAT ORDER

Each step down gives more control and less protection.

WHAT TO TEST

That the generated query is what you intended.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot