
Use Eloquent Relationships to Write Cleaner Code
Relationships are not only for reading data. Creating records through them removes hand-wired foreign keys and a whole class of bugs.
15 posts tagged Laravel.

Relationships are not only for reading data. Creating records through them removes hand-wired foreign keys and a whole class of bugs.

Route closures are convenient until they become the place where business logic hides. Let routes map URLs to actions and nothing more.

Not everything a controller does is a query. File uploads, payments and API calls belong in service classes that every entry point can share.

Single responsibility scales down to methods. Small, well-named methods replace comments, keep changes local and make stack traces readable.

A class should have one reason to change. Here is what that means in a Laravel controller, how to split the work, and where splitting turns into fragmentation.

A controller translates an HTTP request into a response — nothing more. Here is why query and business logic belongs on the model, and where the rule stops applying.