0

I have added a checkbox to my existing submit form that must change from value 0 to 1 if it is activated. But they dont' save the value, it's always 0.

My code:

 <label class="checkbox-inline">
      <input type="checkbox" id="inlineCheckbox1" value="true" name="trackingnumber"> You provide an Tracking Number   
 </label>

ProductController:

if ($request->trackingnumber == 'true') {
    $product->trackingnumber = true;
}

What have I forgotten?

4
  • Can you show more code? Do you run $product->save() somewhere to save it into database? Commented Dec 18, 2017 at 13:46
  • What’s the content of $request->trackingnumber? Have you tried looking at it with dd($request->trackingnumber); for example? Commented Dec 18, 2017 at 13:48
  • Why don't you show us the contents of the request? Commented Dec 18, 2017 at 13:59
  • What you mean with contents of the request? Commented Dec 18, 2017 at 14:01

3 Answers 3

1

Okay i have just change the id="inlineCheckbox1" and works now

Sign up to request clarification or add additional context in comments.

Comments

0

In your ProductController do

if ($request->trackingnumber == 'on') {

and set the value also to "on" in your html and it should work

or you just simply dd($request)

1 Comment

No change, the same... always 0 value
0

in this situation try dd($request) in your controller and check what it contain in that.

Update:

Hey please put checkbox value="1" and then check what value of checkbox is there in request.

4 Comments

please can you share what output you get
and try this dd(Request()) instead of dd($request)
I dont get any output, all other submitted values are saved in DB but "trackingnumber" are always "0"
on the starting of your function you have to write like this public function index(){ dd(Request()); } and check what value it contain

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.