Where is the right place to put the check of an empty value? In the model, or in the controller?
In my model I have this mutator to hash the password before save it in the database:
public function setPasswordAttribute($password)
{
return $this->attributes['password'] = bcrypt($password);
}
But I need to do this check in the controller to prevent update password with an empty value:
if (trim($request->password) != '') {
$user->password = $request->password;
}
Where is the right place to put this check according to SOLID principles?
Well a password is always required right? So in that case you would do that check in the validation of your form. In the case of Laravel a Request class. After that the logical place would be the controller in my opinion
array_filter remove all empty elements of an array, and becouse all my model attributes is required it works.
Yes, I know and I use the $fillable property.