Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tomasosho's avatar

I want to disable my button if a form field value is empty.

The value is gotten from the database. I will need example. I don't need it to submit the form. i just want the button disabled if empty.

0 likes
6 replies
tomasosho's avatar

Can is there no way it can be done with eloquent?

jdc1898's avatar

You can... If you want to do it in the blade, you can still use the IF statement

@if ($disabled) { show the button with a disabled state } @else { show the button with a enabled state } @endif

Amaury's avatar

In you blade template:

<input ... @empty($field) disabled @endempty>
jlrdw's avatar

Many of these types of things are just basics of HTML for example see this:

https://www.w3schools.com/tags/att_input_disabled.asp

You might want to learn a little more about basic HTML, CSS, and some basic JavaScript.

Much of this stuff has nothing to do with laravel or eloquent, but are basic essentials in any modern web programming language.

For example are you familiar with the css:

display:none

I use it all the time for a division I use display block when I need it to show and display none when I don't need it.

These are the types of things that should be practiced either before using laravel, or independently in conjunction with learning laravel.

piljac1's avatar

It's important to note that if you want something dynamic (disable the button if the user empties the field and enable it when the user has typed something in the field), you'll need JavaScript. It cannot be done in HTML/Blade/PHP.

Please or to participate in this conversation.