0

I have a option tag to name 'status'.

blade

<div class="form-group">
    <label class="col-md-3" for="status">Status</label>
    <div class="col-md-9">
        <div class="radio">
            <label>
                <input type="radio" name="status" id="active" value="active">                        Active
            </label>
            <label>
                <input type="radio" name="status" id="deactive" value="deactive">                      Deactive
            </label>
        </div>
    </div>
</div>

Model

protected $fillable = ['name', 'status']

Controller

public function store(Request $request)
    {
        SchoolsList::create($request->all());
        return redirect(route('submit-information.index'));
    }

When I click on submit I see this error.

SQLSTATE[HY000]: General error: 1364 Field 'status' doesn't have a default value

How to when select option value save and add to my database.

2 Answers2

1

It's throwing this error. Because when you submit your form, status column has no value inside it. check your submitted form data & ensure that it has value. Otherwise, make your column nullable using $this->integer('status')->nullable();

Jobayer
  • 1,221
  • 1
  • 14
  • 22
0

You are not selecting anything from the radio button while submitting the value so the key status is having no value in it . Which is throwing you this error as the status column in db needs a value while inserting a new row .

1 - Put some validation before submitting your form for status .

2 - Else go to your db and set a default value as active/deactive/null in the table manually .

3 - Else change the property of the "status attribute" in the table . (Make it varchar manually )

4 - If you are want to do it with code delete the table and create it by Laravel Schema Builder Click Here and there make the status nullable .

  Schema::create('table_1',function ($table){
  $table->nullable('status'); // add other attibutes . refere the url });
sibabrat swain
  • 1,277
  • 8
  • 20