2

I have check box like this:

<input {{isset($shop['private_post'])&&$shop['private_post']=='Yes' ? 'checked' : ''}} id="private_post" value="Yes" type="checkbox" name="private_post">

in controller :

$shop= shop::find($request['id']);
$shop->update($request->all());

In edit mode When I checkbox true work correctly but when I unchecked checkbox dose not work.
I create dynamically checkbox and I can not use this command

If(!isset($request['private_post']))
$request['private_post']=0;
$shop= shop::find($request['id']);
$shop->update($request->all());

2 Answers 2

5

Try this:

In Blade

{!! Form::checkbox('private_post', '1', Input::old('private_post', 1)) !!}

In Controller

$request['private_post'] = isset($request['private_post']) ? 1 : 0;
Sign up to request clarification or add additional context in comments.

6 Comments

I can not use $data['private_post'] = isset($data['private_post']) ? 1 : 0; in controller
I know but my problem is I don`t know which fields is checkbox.
as per your question you mention that 'private_post' is your checkbox.
Yes but in end of post I said that I can not use this commands
No because a lot of files and classes
|
5

I solved it by hidden input

<input type="hidden" value="0" name="private_post">    
<input {{isset($shop['private_post'])&&$shop['private_post']=='Yes' ? 'checked' : ''}} id="private_post" value="Yes" type="checkbox" name="private_post">

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.