使用Laravel雄辩的将文本框中的数组插入数据库

时间:2018-06-26 15:18:47

标签: php laravel eloquent

我有通过jquery表单提交的数据

"<tr><td><input type='checkbox' name='record'></td><td><input name='subjects[]' class='form-control' disabled value='" + name + "'></td><td><input class='form-control' disabled value='" + staff + "'></td><td><input type='hidden' name='staffs[]' class='form-control' value='" + staff_id + "'></td></tr>"

在我的控制器(SubjectsController.php)中,我有

public function store(Request $request)
{
    $subjects = array();
    $subjects = $request->subjects;
    $staff = $request->staffs;


    $subjectSet = [];
    foreach($subjects as $subject){
        $subjectSet[] = [
            'schoolclass_id' => $request->schoolclass_id,
            'name' => $subject,
            'staff_id' => $staff
        ];
    }

    DB::table('subjects')->insert($subjectSet);

提交此文件时,我不断收到为foreach()提供的无效参数

0 个答案:

没有答案