我在laravel中有一個用於將數據保存到數據庫中的函數,出於某種原因,其中一個變量將不會添加到數據庫中,特別是日曆的id 。我曾嘗試在數據庫輸入前後返回變量,並且在兩次都存在,它不會被添加。以下是我迄今爲止:傳遞給函數的laravel值不會傳遞到數據庫中
class SetupPhotoshoot{
public function createListing(Request $request){
$calendarAdd = $this->addToCalendar($request);
$addtoDB = $this->addToDB($request, $calendarAdd['id']);
return $addtoDB;
}
protected function addToDB($request, $calendarID){
//Some code here
return $calendarID; //This is to see if the id exists inside the function, which it does.
$newSchedule = new Schedule;
$addtoDB = $newSchedule->create({
//Add a bunch of fields
'services_id' => $request->Package,
'appt_time' => $request->DateTime,
'total' => $request->total,
'calendar_id' => $calendarID //This is where I want the id to be added, but it isn't working.
});
return $calendarID; //I tried returning after adding to DB to see if it somehow got lost between before adding to DB and after, but it still returned.
//NOTE: the two individual returns were NOT used at the same time. I commented out one to test if the other returned, so it IS NOT because I used return multiple times.
}
}
所有其他數據被添加到數據庫中正確的,除了calendar_id.
它說,特定的錯誤是「常規錯誤:1364字段‘CALENDAR_ID’沒有缺省值「。當我允許空值時,它只會將「null」添加爲數據庫中的值。下面是它看起來像在數據庫中(這是MYSQL):
Name: calendar_id
Type: varchar(191) utf8mb4_unicode_ci
Null: Yes
Default: None
怎樣的schedule.create()是什麼樣子? – Shadow