php - 在 Laravel 的另一个表中保存输入字段
问题描述
所以我现在拥有的是: 一个 CRUD 应用程序:一个注册表和表格,以及一个 Extraregistration 表,我想在其中保存一些注册字段。Extraregistration 表有一个registration_id。
注册控制器
$registration->ris_firstname = $request->firstname;
$registration->ris_lastname= $request->lastname;
$registration->ris_email = $request->email;
html
<label>Firstname</label>
<input type="text" name="firstname" id="firstname" class="form-control" data-blocked="<>{}" value="{{ ($cache['firstname'] ?? old('firstname') ?? $registration->ris_firstname ?? '') }}" required>
<label>Lastname</label>
<input type="text" name="lastname" id="lastname" class="form-control" data-blocked="<>{}" value="{{ ($cache['lastname'] ?? old('lastname') ?? $registration->ris_lastname ?? '') }}" required>
<label>E-mail</label>
<input type="text" name="email" id="email" class="form-control" data-blocked="<>{}" value="{{ ($cache['email'] ?? old('email') ?? $registration->ris_email ?? '') }}" required>
外注册控制器
$extraregistration->iea_price = $request->price;
$extraextraregistration->iea_registration_id = $registration_id;
html
<label>Price</label>
<input type="text" name="price" id="price" class="form-control" data-blocked="<>{}" value="{{ ($cache['price'] ?? old('price') ?? $extraregistration->iea_price ?? '') }}" required>
我想将名字和姓氏保存到 extraregistration 表中,而不是保存在普通注册表中。因此,当我添加注册时,名字和姓氏会转到 extraregistration 表,在数据库的 Extraregistration 表中的 registration_firstname 字段中提前谢谢!
解决方案
在 RegisterController 里面创建函数。
$extraregistration = new YourModel();
$extraregistration->ris_firstname = $request->firstname;
$extraregistration->ris_lastname= $request->lastname;
$extraregistration->save();
推荐阅读
- authorization - 带通配符的 Istio AuthorizationPolicy
- python - Pyinstaller --add-data FileNotFoundError 同时保存数据
- docker - Docker 将非空容器文件夹挂载到主机
- google-apps-script - 谷歌表格脚本编辑器删除不需要的行
- reactjs - 如何导航?(未定义不是对象(评估“this.props”)
- azure-logic-apps - 使用逻辑应用向 JIRA 问题添加附件
- python - 如何计算 bot uptime 命令所用的时间?Python
- python - 即时更改 numpy 数组大小
- sql - 在同一列中计算 1 之间的零
- c - 安装和使用共享库