Skip to content
Advertisement

How to active and inactive boolean in Laravel

I want to know how to make a Boolean data true or false in database whenever my button is clicked. I already can perform a true when button is clicked, I want to know how to make it false. I hope I can get a answer thank you! BTW, this is my first time to post a question here and the source code are from Code With Stein from YT a big credits. Here are some of codes I used.

My code for my update form

JavaScript

My code for route

JavaScript

My code for my controller

JavaScript

UI change when I the button clicked

JavaScript

Screenshot of UI

Advertisement

Answer

If you want to make it false (or like toggle), can try swap the value with !

something like this

JavaScript

I’ve tested here

https://web.tinkerwell.app/#/snippets/dc8a7b9f-59a6-4c07-84ca-1bb2fc8c1da4

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement