【发布时间】:2021-08-09 20:27:53
【问题描述】:
在保存新数据之前,我曾尝试从booking 表中获取auto increment ID,但我一直有错误。
这是控制器中的代码:
public function addAppointment(Request $request) {
$user = auth()->user();
$booking = new Booking();
$booking->vac_center_id = $request->get('vaccination_center');
$booking->vac_id = $request->get('vaccination_id');
$booking->date_of_shot = $request->get('date_of_shot');
$booking->time = $request->get('time');
$booking->shot_number = $request->get('shot_number');
$booking->isDone = 0;
$booking->isCancelled = 0;
$booking->user_id = $user->id;
$booking->save();
$booking = new BookingHasVaccinationCenters();
//here below I want to get the auto increment id
$booking->booking_id->id;
$booking->vac_center_id = $request->get('vaccination_center');
$booking->save();
return redirect('/home');
}
这是我上次尝试这样做时遇到的错误:
尝试在 null 上读取属性“id”
【问题讨论】:
标签: php laravel eloquent laravel-8