Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.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
Laravel 5.4 如何为多个数组值更新现有行添加在laravel中的表中插入新行_Laravel 5.4_Laravel Query Builder - Fatal编程技术网

Laravel 5.4 如何为多个数组值更新现有行添加在laravel中的表中插入新行

Laravel 5.4 如何为多个数组值更新现有行添加在laravel中的表中插入新行,laravel-5.4,laravel-query-builder,Laravel 5.4,Laravel Query Builder,我有一个带有数组输入值的数据表,如下所示 <table> <tr> <td>Name</td> <td>Email</td> <td>Phone</td> </tr> <tr> <td><input type="text" name="user_id[]" value="1"></td

我有一个带有数组输入值的数据表,如下所示

<table>
    <tr>
    <td>Name</td>
    <td>Email</td>
    <td>Phone</td>
    </tr>
    <tr>
        <td><input type="text" name="user_id[]" value="1"></td>
        <td><input type="text" name="name[]"></td>
        <td><input type="text" name="email[]"></td>
        <td><input type="text" name="phone[]"></td>
    </tr>
    <tr>
        <td><input type="text" name="user_id[]" value="2"></td>
        <td><input type="text" name="name[]"></td>
        <td><input type="text" name="email[]"></td>
        <td><input type="text" name="phone[]"></td>
    </tr>
    <tr>
        <td><input type="text" name="user_id[]" value=""></td>
        <td><input type="text" name="name[]"></td>
        <td><input type="text" name="email[]"></td>
        <td><input type="text" name="phone[]"></td>
    </tr>
    <tr>
        <td><input type="text" name="user_id[]" value=""></td>
        <td><input type="text" name="name[]"></td>
        <td><input type="text" name="email[]"></td>
        <td><input type="text" name="phone[]"></td>
    </tr>
</table>

但它不能正常工作。有人能为我提供解决方案吗?

您应该使用
foreach
循环来循环字段,并在字段是否为空时执行某些操作

也许,像这样的事情会对你有所帮助

$fields = Input::get('user_id');

foreach($fields as $field)
{
    if(! empty($field))
    {
        // field is not empty
        // update here
    }
    else
    {
        // field is empty
        // do something here
    }
}

伟大的!就连我也在用同样的流程工作。谢谢你
$fields = Input::get('user_id');

foreach($fields as $field)
{
    if(! empty($field))
    {
        // field is not empty
        // update here
    }
    else
    {
        // field is empty
        // do something here
    }
}