0

I have an input form with the name student_lastname[].

<div class="form-group col-md-6 col-lg-6 col-xl-6 col-sm-6">
     <label for="inputLastName">Last Name </label>
     <input type="text" class="form-control" id="inputLastName_1" name="student_lastname[]" placeholder="" >
</div>

If it is not filled in it will automatically be filled with the string "" or null, and if the value is filled in, then send the filled value. How can I create such conditions?

jkdev
  • 11,360
  • 15
  • 54
  • 77
  • 1
    set `student_lastname` nullable in database or `$table->string('student_lastname)->nullable();` – Karan Dec 04 '19 at 04:24

1 Answers1

0

Create a new migration that sets your column values to be nullable, to do that, refer to this question. Then, in your controller, check whether the requested data is empty, if so, do not set any value to the field. It could look something like this (assuming the form makes a POST request):

// your code here
if(request('student_lastname[]')){
// set student last name
}
// if the field was left empty, student's last name will be null 
// rest of your code
KiprasT
  • 370
  • 5
  • 14