I have a system_name field that is nullable that I want to validate for uniqueness if the input is not null.
As based on the recommended solutions given by others, it can just be
$this->validate($request, [
'system_name' => 'nullable|unique:systems'
]);
Why is it that this solution work? Given that when a null value is entered for system_name, shouldn't it pass the nullable rule but fail the unique rule as the null value is not unique since it has been used before?
Can I also enquire what is the difference between encapsulating the rule with '' vs [ ] ? As shown by the validation done on username and email
public function rules()
{
return [
'username' => 'required|min:8',
'email' => ['required', Rule::unique('users')]
];
}