php - Queries of checkbox on octobercms/laravel

416

I would like to know how i can get the current status of checkbox without saving the model in octbercms or laravel. Thanks. The following is what i would like to do:

 public function button_pressed(){     
    if(checked){
        //do something
    }
 }
953

Answer

Solution:

To check if a checkbox is checked you basically have to check if the input exists, so using the request object:

use Illuminate\Http\Request;

public function button_pressed( Request $request ){
    if( $request->has('checkbox_name') ){
        // checkbox is check
    } else {
        // checkbox is NOT check
    }
}

EDIT:

public function button_pressed(){
    if( request()->has('checkbox_name') ){
        // checkbox is check
    } else {
       // checkbox is NOT check
    }
}

People are also looking for solutions to the problem: Create a Laravel / PHP script that runs periodically e.g. every 1 week to update my MySQL database with calls to an api

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.