Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/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
Php 具有动态表行和数据库自动填充的Laravel表单模型绑定_Php_Laravel - Fatal编程技术网

Php 具有动态表行和数据库自动填充的Laravel表单模型绑定

Php 具有动态表行和数据库自动填充的Laravel表单模型绑定,php,laravel,Php,Laravel,拉威尔5.2 我的创建表单能够通过jquery动态添加tr行,以便将更多数据插入数据库。如何使用表单模型绑定(或其他方式)提取此数据并自动填充编辑表单 因Nazmul Hasan评论而更新: 代码示例: 视图:(供应商与其他供应商有很多关系) 控制器:(更新)-未知代码 如何告诉Laravel数据库中要更新的行?根据我对您的问题的理解,您可以尝试以下方法: 1考虑到你已经第一手创建了模型,请获取所有模型。 如果尚未创建模型,可以尝试: php artisan make:model Example

拉威尔5.2

我的创建表单能够通过jquery动态添加tr行,以便将更多数据插入数据库。如何使用表单模型绑定(或其他方式)提取此数据并自动填充编辑表单

因Nazmul Hasan评论而更新:

代码示例:

视图:(供应商与其他供应商有很多关系)

控制器:(更新)-未知代码


如何告诉Laravel数据库中要更新的行?

根据我对您的问题的理解,您可以尝试以下方法:

1考虑到你已经第一手创建了模型,请获取所有模型。 如果尚未创建模型,可以尝试:

php artisan make:model Example
为了举例说明,让我们称之为示例模型

以下可能是它的数据:

----------------------------------------
ID       Name        Age         Phone
----------------------------------------
1        Sam         20          12345
2        Mia         23          11234
2首先从控制器中取出所有数据 3用你的数据填写表格 您需要将数据放在这一步中,使用foreach循环并使用'value'属性将值放在html标记中

<form>
@foreach($example as $e)

    <div class="input-group">
        <h2 class="input-group">Category's Name</h2>
        <!-- the $e->Name is from the data we passed previously -->
        <input type="text" class="form-control input-lg" name="Name" value="{{ $e->Name }}">
    </div>

@endforeach
</form>

@foreach($e为示例)
类别名称
@endforeach
猜猜什么会填充文本输入?那就是萨姆


据我所知,文本输入中的“value”属性是您目前正在查看的内容。

根据我对您的问题的理解,您可以尝试以下内容:

1考虑到你已经第一手创建了模型,请获取所有模型。 如果尚未创建模型,可以尝试:

php artisan make:model Example
为了举例说明,让我们称之为示例模型

以下可能是它的数据:

----------------------------------------
ID       Name        Age         Phone
----------------------------------------
1        Sam         20          12345
2        Mia         23          11234
2首先从控制器中取出所有数据 3用你的数据填写表格 您需要将数据放在这一步中,使用foreach循环并使用'value'属性将值放在html标记中

<form>
@foreach($example as $e)

    <div class="input-group">
        <h2 class="input-group">Category's Name</h2>
        <!-- the $e->Name is from the data we passed previously -->
        <input type="text" class="form-control input-lg" name="Name" value="{{ $e->Name }}">
    </div>

@endforeach
</form>

@foreach($e为示例)
类别名称
@endforeach
猜猜什么会填充文本输入?那就是萨姆


据我所知,文本输入中的“value”属性是您目前正在查找的内容。

因此,根据Nazmul Hasan的评论,我的控制器中有以下存储功能

更新控制器:

        foreach ($request->get('SupplierExtraName') as $key => $row) {
            Extra::where('id', $key)->update([
                'name' => $request->SupplierExtraName[$key],
                'cost' => $request->SupplierExtraCost[$key],
            ]);
更新视图:

@foreach ($supplier['SupplierExtra'] as $extra)
            <tr class="master">
                <td>{!! Form::text("SupplierExtraName[$extra->id]", $extra->name, ['class' => 'form-control']) !!}</td>
                <td>{!! Form::text("SupplierExtraCost[$extra->id]", $extra->cost, ['class' => 'form-control']) !!}</td>
                <td></td>
                <td>
                    <button type="button" class="btn btn-primary btn-md addRow">
                        <span class="glyphicon glyphicon-plus-sign"></span> Add a row
                    </button>
                </td>
            </tr>
        @endforeach
@foreach($supplier['SupplierExtra']作为$extra)
{!!Form::text(“SupplierExtraName[$extra->id],$extra->name,['class'=>'Form control'])
{!!Form::text(“SupplierExtraCost[$extra->id],$extra->cost,['class'=>'Form control'])
添加一行
@endforeach

因此,根据Nazmul Hasan的评论,我的控制器中有以下存储功能

更新控制器:

        foreach ($request->get('SupplierExtraName') as $key => $row) {
            Extra::where('id', $key)->update([
                'name' => $request->SupplierExtraName[$key],
                'cost' => $request->SupplierExtraCost[$key],
            ]);
更新视图:

@foreach ($supplier['SupplierExtra'] as $extra)
            <tr class="master">
                <td>{!! Form::text("SupplierExtraName[$extra->id]", $extra->name, ['class' => 'form-control']) !!}</td>
                <td>{!! Form::text("SupplierExtraCost[$extra->id]", $extra->cost, ['class' => 'form-control']) !!}</td>
                <td></td>
                <td>
                    <button type="button" class="btn btn-primary btn-md addRow">
                        <span class="glyphicon glyphicon-plus-sign"></span> Add a row
                    </button>
                </td>
            </tr>
        @endforeach
@foreach($supplier['SupplierExtra']作为$extra)
{!!Form::text(“SupplierExtraName[$extra->id],$extra->name,['class'=>'Form control'])
{!!Form::text(“SupplierExtraCost[$extra->id],$extra->cost,['class'=>'Form control'])
添加一行
@endforeach

您必须手动填充动态添加的行。您可以尝试在编辑模式下使用foreach循环,但必须手动填充动态添加的行。您可以尝试在编辑模式下使用foreach循环