Pare de usar first(): existe um método do Eloquent feito pra 'só pode existir um'
O first() esconde bugs de dados duplicados. Conheça o sole() do Eloquent, que retorna um registro só e reclama quando aparece mais de um.
Tag archive
O first() esconde bugs de dados duplicados. Conheça o sole() do Eloquent, que retorna um registro só e reclama quando aparece mais de um.
Deletou um registro em produção e o cliente pediu de volta? Soft Deletes marca como apagado sem sumir do banco. Veja como usar (e as pegadinhas).
Ainda faz json_decode na mão no seu model? O Eloquent tem uma penca de casts prontos que quase ninguém usa. Bora conhecer os melhores.

Stop passing raw ints and strings around your app. Map Money and Email value objects to columns with custom Eloquent casts, edge cases and all.

with('commentable') looks eager. Then the nested relations fall back to lazy queries. Here's why morphTo needs morphWith, with query counts.

Flexible API filters often look elegant at first and turn into maintenance debt later. This post compares scopes, query objects, packages, JSON filters, and relationship filters with a bias toward what stays understandable as the API grows.

Find any Eloquent method instantly. 27 groups, hundreds of methods, one search.

Eloquent's hydration cost is real. Five Laravel cases where the query builder runs 10× faster and your team blames the database instead.

When the template knows your column names, the view is coupled to the database. Read DTOs and view models fix it, and the tests get cleaner too.

Keep Eloquent for persistence, build a parallel domain entity, route callers through a repository, retire the model feature by feature.

Active Record is convenient until your domain rules turn into a maze. Keep Eloquent for persistence and put the business behavior where it belongs.

A practical way to introduce typed objects around Eloquent where they actually help, without adding a lot of mapping layers or turning Laravel into a parallel ORM experiment.