There is a form request UpdateUserRequestthat checks the value of a field against its rules defined in rulesmathod. It has rules () and authorize () methods by default. I want to prevent checking and updating empty fields (e.g. password).
using sometimesin the rules is not useful, since html entries will be present in the POST request, even if they are empty.
array:6 [▼
"_method" => "PATCH"
"_token" => "Cz79rRez2f6MG0tTU17nVwXD0X1lNGH1hA7OORjm"
"name" => "john"
"email" => "mymail@gmail.com"
"password" => ""
"password_confirmation" => ""
]
so I have to remove the empty keys of the POST request before using sometimesin the rules.
Q: where is the best place to clear the Request array?
Is there any way to create laravel to handle such situations?
P.S: :
@Bogdon , , , , :
all()
class RegistrationRequest extends Request
{
...
public function all()
{
$attributes = parent::all();
if(isset($attributes['password']) && empty($attributes['password']))
{
unset($attributes['password']);
}
$this->replace($attributes);
return parent::all();
}
...
}