php - PHP - 在另一个表中,保存输入字段

CRUD应用程序:Registration表和表单,以及Extraregistration表,我要在Extraregistration保存注册中的某些字段,Extraregistration表有一个registration_id 。

RegistrationController


$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>



ExtraregistrationController


$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表中,而不是在普通注册表中。

时间:

在RegisterController内部创建函数。


$extraregistration = new YourModel();


$extraregistration->ris_firstname = $request->firstname;


$extraregistration->ris_lastname= $request->lastname;


$extraregistration->save();



...