SQLSTATE[22007]:无效的日期时间格式:1366 不正确的整数值:第 1 行的列 'infraction_id' 的 '["1","3","66","68"]'
SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: '["1","3","66","68"]' for column 'infraction_id' at row 1
我想保存全部数据,但需要数组,数据格式错误
blade
@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]: Invalid datetime format: 1366 Incorrect integer
value: '["1","3","66","68"]' for column 'infraction_id' at row 1 (SQL:
insert into inspections
(infraction_id
, encouragement_id
,
user_id
, requisition_id
, updated_at
, created_at
) values
(["1","3","66","68"], 1, 1, 1, 2018-11-08 10:40:45, 2018-11-08
10:40:45))
当您获得 infraction_id
的 n 个值数组时(当您在 HTML 中定义它时,您使用 name="infraction_id[]"
)您将需要添加多个记录...
foreach ( $request->infraction_id as $infraction_id ) {
$inspection = new Inspection();
$inspection->infraction_id = (int)$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');
我想保存全部数据,但需要数组,数据格式错误
blade
@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]: Invalid datetime format: 1366 Incorrect integer value: '["1","3","66","68"]' for column 'infraction_id' at row 1 (SQL: insert into
inspections
(infraction_id
,encouragement_id
,user_id
,requisition_id
,updated_at
,created_at
) values (["1","3","66","68"], 1, 1, 1, 2018-11-08 10:40:45, 2018-11-08 10:40:45))
当您获得 infraction_id
的 n 个值数组时(当您在 HTML 中定义它时,您使用 name="infraction_id[]"
)您将需要添加多个记录...
foreach ( $request->infraction_id as $infraction_id ) {
$inspection = new Inspection();
$inspection->infraction_id = (int)$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');