Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果未填写,则会自动用字符串“quot&引用;或空_Php_Laravel_Validation - Fatal编程技术网

Php 如果未填写,则会自动用字符串“quot&引用;或空

Php 如果未填写,则会自动用字符串“quot&引用;或空,php,laravel,validation,Php,Laravel,Validation,我有一个名为student\u 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_lastn

我有一个名为
student\u 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>

如果未填写,则会自动用字符串
或null填写,如果已填写值,则发送已填写的值。如何创建这样的条件?

创建一个新的迁移,将列值设置为可空,为此,请参考此。然后,在控制器中,检查请求的数据是否为空,如果为空,请不要为字段设置任何值。它可能看起来像这样(假设表单发出
POST
请求):


在数据库中设置
student\u lastname
可为null或
$table->string('student\u lastname)->可为null()
// 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