Lets say I have my business logic in a Model
, for example in Student.php
(that extends Model
).
In my controller, I get an instance of that model: $myStudent = Student::find(1);
Then I want to perform some action on it, say: $myStudent->graduate();
But my business logic says that because of some condition, this action can't be performed. How do I pass this information to the controller? Via a return value? Via an exception? Some other way?
-
Return value: If I return a value (say, 0:success, 1:Error because average is below 70, 2:Error because average is below 50), part of the business logic would leak into the controller, which should be avoided.
-
Exception: If the request is successful the normal execution of the code continues, but if not I throw an exception along with some text that is displayed to the user.
Is an exception the way to go? Any other way to do this? Thanks!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire