At first I used exceptions with saveOrFail() which worked, but I kept accidentally using save() which didn't. So I switched to enabling $throwValidationExceptions so that I'm always alerted when validation fails. I also had trouble with $rules and $messages so switched to using $rulesets and $validationMessages. Here is an example that works for me, hope this helps someone:
class User extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait, ValidatingTrait;
protected $throwValidationExceptions = true; // always throw validation exceptions
/*protected $rules = [
'username' => 'unique'
];*/
protected $rulesets = [
'creating' => [
'username' => 'required|unique'
],
'updating' => [
'id' => 'required'
],
'deleting' => [
'id' => 'required'
]
];
protected $validationMessages = [
'username.unique' => "That username is not available."
];
// ...
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community