input fields are always sent. only checkboxes are not sent when not checked.
Laravel will then convert empty strings to null.
Have you tried adding nullable to the url validation?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I have a simple form for uploading files, which can be done either by selecting a local file (<input type="file">) or by entering a URL. (<input type="url">) To that end, I validate the request like so:
$request->validate([
'image' => [ 'image', 'required_without:url' ],
'url' => [ 'url', 'required_without:image' ],
]);
This works fine when submitting a URL, but I have recently discovered that when uploading a file, the URL field also gets passed, and is received in Laravel as null, failing the validation. It seems like I can set the url field as nullable, and then check whether it isset, rather than request->has, which I've been doing so far, but I'm unsure of whether there is a better solution that I'm missing.
Please or to participate in this conversation.