我收到此错误:
SQLSTATE [23000]:违反完整性约束:1452无法添加或 更新子行:外键约束失败 (prj_tvto.activities,约束活动_school_id_foreign FOREIGN KEY(school_id)参考学校(id))(SQL:插入活动 (school_id,cluster_id,group_id,updated_at,created_at)值(0, 2,3,2018-08-14 05:02:28,2018-08-14 05:02:28))
在控制器中
public function store(Request $request, SchoolsList $schoolsList)
{
if($request->ajax()) {
$activity = new Activity();
$activity->school_id = intval($request->school_id);
$activity->cluster_id = $request->cluster_id;
$activity->group_id = $request->group_id;
$activity->save();
return response()->json(['data_activity' => $request->all(), 'id' => $activity->id]);
}
}
还有Ajax
var school_id = {school_id: data_school.id} ;
console.trace(school_id);
我正在使用laravel 5.4