SQLSTATE [22007]:无效的日期时间格式:1366错误的整数值:第1行的列'infraction_id'的'[“ 1”,“ 3”,“ 66”,“ 68”]'

时间:2018-11-08 07:37:43

标签: php laravel-5.4

我正在尝试保存整个数据,但是我需要进行阵列处理,并且发生数据格式错误。

刀片

@foreach($infractions as $infraction)
    <tr>
        <th>{{ $infraction->title }}</th>
        <td>
            <input type="checkbox" name="infraction_id[]" value="{{ $infraction->id }}" data-toggle="toggle" data-on="Yes" data-off="No" data-onstyle="success" data-offstyle="danger" data-score="{{ $infraction->score }}">
        </td>
    </tr>
@endforeach

控制器

public function store(Request $request)
{
    $inspection = new Inspection();
    $inspection->infraction_id = $request->infraction_id;
    $inspection->encouragement_id = 1;
    $inspection->user_id = auth()->user()->id;
    $inspection->requisition_id = $request->input('requisition_id');
    $inspection->save();
    $inspection->requisitions()->update(['status' => 1]);
    return redirect()->route('inspection-results.index');
}

我看到此错误

  

SQLSTATE [22007]:无效的日期时间格式:1366不正确的整数   值:第1行的“ infraction_id”列的'[“ 1”,“ 3”,“ 66”,“ 68”]'(SQL:   插入inspectionsinfraction_idencouragement_id,   user_idrequisition_idupdated_atcreated_at)个值   ([[“ 1”,“ 3”,“ 66”,“ 68”],1,1,1,2018-11-08 10:40:45,2018-11-08   10:40:45))

enter image description here

1 个答案:

答案 0 :(得分:2)

当您获得activity的n个值数组时(在HTML中定义时,您使用infraction_id)将需要添加多个记录...

name="infraction_id[]"