如何将school_id
更改为int以保存在数据库中?我在laravel和ajax中保存到数据库时遇到问题。我想school_id
更改为变量(我认为)以进行保存。当我存储在数据库中时,网络标签中出现500错误。
我的代码在这里
<script type="text/javascript">
$("#schools").submit(function (event) {
event.preventDefault();
province_id = $('#province_id').val();
city_id = $('#city_id').val();
center_id = $('#center_id').val();
$.post("{{ route('schools-list.store') }}", {province_id:province_id, city_id:city_id, center_id:center_id}, function (data_school) {
var school_id = {school_id: data_school.id} ;
console.log(school_id);
});
});
</script>
控制器
public function store(Request $request, SchoolsList $schoolsList)
{
if($request->ajax()) {
$activity = new Activity();
$activity->school_id = $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]);
}
}