首页 > 解决方案 > 在 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 字段中提前谢谢!

标签: phplaravel

解决方案


在 RegisterController 里面创建函数。

$extraregistration = new YourModel();
$extraregistration->ris_firstname = $request->firstname;
$extraregistration->ris_lastname= $request->lastname;
$extraregistration->save();

推荐阅读