Let's say I'm writing a Laravel controller that has a function: make a simple search on a model and do anything with the result. Something like this (without any validation, for simplicity):
public function search($name)
{
$person = Persons:where('name', $name)->first();
doSomethingWith($person);
// ...
}
Should I move this tiny Eloquent code to the Person
model in a dedicated function? Usually I write all the "complex" operations to the Models to have short and readable controllers, but when I have to do little operations like this I always find that moving a single line of code (even if it is directly related to the database) into a separated model function will bring too much overhead to my code.
Aucun commentaire:
Enregistrer un commentaire