octobercms - 十月cms如何将后端数据保存在两个表中
问题描述
我有两个表Brands
,BrandTimings
我想用取货和送货时间来保存品牌,我有一个表格,我要提交所有数据我收到错误,我理解错误,但我不知道如何分配取货和送货时间到一个变量并删除它们,然后使用 afterSave(),用新创建的品牌 ID 将它们保存在 BrandTimings 中,我尝试过 beforeSave(),但我不明白该怎么做,因为 10 月 cms 文档没有示例,
未找到列:1054 '字段列表'中的未知列 'pickup_time'(SQL:插入
offline_mall_brands
(name
、、、、、、、、、、、)值( ASDEid
、 1pickup_time
、[ "0"、"1"]、["delivery_time
2slug
" ,"3"], zip-jet, , , 2020-06-04 10:19:17, 2020-06-04 10:19:17))" 在 /home/vagrant/code/cml/vendor 的第 664 行/laravel/framework/src/Illuminate/Database/Connection.phpwebsite
description
updated_at
created_at
品牌
id name location
1 Inspire Lacer
品牌时间
id brand_id pickup_time delivery_time
1 1 08:00 15:00
1 1 09:00 16:00
1 1 10:00 17:00
1 1 11:00 18:00
解决方案
哦,我明白发生了什么。Brands
没有delivery_time,但BrandTimings
有。一种可行的方法是在您的 php.ini 文件中。现在你没有提到这些模型是否相互关联,所以我不会那样写。而且你没有展示你现在是如何尝试保存它的,所以我要弥补它。这是一个例子:
public function onSaveBrandTimings() {
// Get inputs and you would validate them as well
$name = Input::get('name');
$location = Input::get('location');
$pickup_time = Input::get('pickup_time');
$delivery_time = Input::get('deliver_time');
if ($validates == true) {
// Create Brand
$brand = New Brands;// Create brand instance but won't have id
$brand->name = $name;
$brand->location = $location;
$brand->save(); // Saving the brand will fill in the ID in the instance
// Create BrandTimings
$brandTimings = new BrandTimings;
$brandTimings->brand_id = $brand->id;
$brandTimings->pickup_time = $pickup_time;
$brandTimings->delivery_time = $delivery_time;
$brandTimings->save();
// Return a statment or a partial update or a redirect
return 'Success'
} else {
return 'Failed'
}
}
推荐阅读
- r - 在 R 中,使用 rgl 包,我可以更改窗口标题吗?
- javascript - 如何从Javascript中的数字数组中删除前导零
- android - 是否可以在应用程序的存储空间中安装 APK 以防止它出现在手机的开始屏幕上?
- python - 如何迭代多个数据帧并将值添加到python中的新数据帧
- r - 为什么单选按钮不适用于两个不同的 tabPanel()s(闪亮的应用程序)中的日期输入选择?
- facebook - 如何在不使用登录的情况下使用令牌初始化 Facebook Javascript SDK?
- python - 如何在 matplotlib 中绘制日期
- arm - 为什么mbed生成不同大小的bin文件在线编译和离线编译(导出gcc_arm makefile)
- sorting - 为什么这两个 GREP 命令给出不同的结果?
- sql-server - SQL组合两个具有相同行数的表的列