Laravel:从input :: get()返回null

时间:2014-09-15 13:02:11

标签: php laravel laravel-4

我需要一个动态表单,它是根据数据库条目创建的。要将数据输入数据库,这也需要是动态的。出于某种原因,我的表格价值为空。

我的表单循环

@foreach ($keyAccounts as $keyAccount)
        {{ Form::label($keyAccount->name, $keyAccount->name.':', array('class' => '')) }}
        {{ Form::text($keyAccount->name)}}<br />
    @endforeach

返回

<label for="hsbc dad" class="">hsbc dad:</label>
        <input name="hsbc dad" type="text" id="hsbc dad"><br />
                <label for="sdsad" class="">sdsad:</label>
        <input name="sdsad" type="text" id="sdsad"><br />
                <label for="dfffff" class="">dfffff:</label>
        <input name="dfffff" type="text" id="dfffff"><br />

提交表单后,它会调用操作控制器并运行以下代码

foreach($keyAccounts as $keyAccount){
        $assignedAccount = new AssignedAccount;
        $assignedAccount->contribution_id = $last_con_id->contribution_id;
        $assignedAccount->key_account_id = $keyAccount->key_account_id; 
        $assignedAccount->year_to_date = Input::get($keyAccount->name);
        $assignedAccount->save();
    }

即使填写了数据,我也会在SQL错误中获取year_to_date变量为null。

这是我的输入:: get()

的var_dump
NULL string(1) "3" string(1) "3"

我不知道为什么但第一个条目为空。数据库中总共有三个条目,没有名称变量为null

1 个答案:

答案 0 :(得分:2)

自动转换为存在空格字符的下划线。删除空格字符或转换为下划线。尝试输入:: get(&#39; hsbc_dad&#39;)

Heres another example

相关问题