Ahsan
Ahsan

Reputation: 1359

Laravel how to store value based on checkbox checked

I am trying to store 1 if checkbox is checked, otherwise 0. The form is

<x-checkbox name="visibility" id="visibility">{{ __('Make this visible') }}</x-checkbox>

In the controller, it is only storing the first value of the condition. This is always storing 0.

$request->visibility = 'checked' ? $package->visibility = 0 : $package->visibility = 1;

This is always storing 1.

$request->visibility = 'checked' ? $package->visibility = 1 : $package->visibility = 0;

Thanks in advance.

Upvotes: 0

Views: 379

Answers (1)

STA
STA

Reputation: 34668

This is working for me :

$model->visibility = ($request->visibility) ? '1' : '0';

Upvotes: 1

Related Questions