fsdolphin
4579
15
Eloquent

What is the proper way to check a boolean from a DB

Posted 3 years ago by fsdolphin

Hi,

I'm trying to check if a boolean is true or false, I get true when it is set to true (1) but I don't get anything when it is set to false (0).

The boolean field is called showBanner and I'm checking it as follow...

$banners = \App\Banner::where('showBanner', '1')->get(['showBanner']);

foreach($banners as $banner){
    $result = $banner->showBanner;
    if($result == 1){
        return "It's TRUE";
    }
    else{
        return "It's FALSE";
    }
}

What is the proper way to check booleans?

Also, I'm not even sure if the way I'm retrieving the field is the most efficient way.

FYI - I also tried if($result == true) and if($result == "1")

Thanks

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.