Laravel 如何从一个页面获取 id 到另一个页面
How to get id from one page to another page in Laravel
我有一个页面可以从用户那里获取一些数据,这些数据将保存在 first_forms
table 中,但是我在下一页的 table 中还有其他字段,它们为空。
这是 first_forms
table :
在此table、project_name
、customer_name
、buyer
、response
、model
会在第一步中保存第一页choose.blade.php
这是控制器中的存储函数:
FirstForm::create([
'model' => $request['model'],
'project_name' => $request['project_name'],
'customer_name' => $request['customer_name'],
'buyer' => $request['buyer'],
'response' => $request['response'],
]);
return view('Form2.firstForm');
如您所见,first_forms
table 中的其他字段将为空。此用户重定向到下一页后 firstForm
。现在在此页面中,用户必须完成其他字段,如:airflow
、tcp
、compress_number
等。我希望当用户单击此页面中的提交时,此页面中的新字段保存在first_forms
中的上一行 table 谁在上一页中完成了,我该怎么做?
我想我必须获取谁完成了上一页并在新页面中使用新字段更新行的 ID,但我不知道如何获取 ID 和更新行。主键是 id
.
这是 first_forms
table 当用户完成第一页时:
这是谁完成了第一页的数据。在下一页上,这些字段为空,必须在此行中完成。
You can simply check that
$first = FirstForm::create([
'model' => $request['model'],
'project_name' => $request['project_name'],
'customer_name' => $request['customer_name'],
'buyer' => $request['buyer'],
'response' => $request['response'],
]);
//Below line will re-retrieve the record along with primary key which is `id`
$first = $first->fresh();
return view('Form2.firstForm',compact('first'));
在视图中,您可以访问插入的数据,例如 $first->id
现在将您的 ID 放在 nextform 的隐藏字段中,并根据该 ID 更新您的记录。您甚至可以在 nextform
的只读字段中显示先前插入的记录
在您的下一个表单视图中
<input type="hidden" name="update_id" value="{{ $first->id ?? '' }}" />
当您提交包含所有其他字段的下一个表单时,您也会获得隐藏的 ID。所以再次在你的控制器方法中你会做类似
的事情
FirstForm::where('id',request('update_id'))->update([
//here goes your other fields of the nextform
]);
我有一个页面可以从用户那里获取一些数据,这些数据将保存在 first_forms
table 中,但是我在下一页的 table 中还有其他字段,它们为空。
这是 first_forms
table :
在此table、project_name
、customer_name
、buyer
、response
、model
会在第一步中保存第一页choose.blade.php
这是控制器中的存储函数:
FirstForm::create([
'model' => $request['model'],
'project_name' => $request['project_name'],
'customer_name' => $request['customer_name'],
'buyer' => $request['buyer'],
'response' => $request['response'],
]);
return view('Form2.firstForm');
如您所见,first_forms
table 中的其他字段将为空。此用户重定向到下一页后 firstForm
。现在在此页面中,用户必须完成其他字段,如:airflow
、tcp
、compress_number
等。我希望当用户单击此页面中的提交时,此页面中的新字段保存在first_forms
中的上一行 table 谁在上一页中完成了,我该怎么做?
我想我必须获取谁完成了上一页并在新页面中使用新字段更新行的 ID,但我不知道如何获取 ID 和更新行。主键是 id
.
这是 first_forms
table 当用户完成第一页时:
这是谁完成了第一页的数据。在下一页上,这些字段为空,必须在此行中完成。
You can simply check that
$first = FirstForm::create([
'model' => $request['model'],
'project_name' => $request['project_name'],
'customer_name' => $request['customer_name'],
'buyer' => $request['buyer'],
'response' => $request['response'],
]);
//Below line will re-retrieve the record along with primary key which is `id`
$first = $first->fresh();
return view('Form2.firstForm',compact('first'));
在视图中,您可以访问插入的数据,例如 $first->id
现在将您的 ID 放在 nextform 的隐藏字段中,并根据该 ID 更新您的记录。您甚至可以在 nextform
在您的下一个表单视图中
<input type="hidden" name="update_id" value="{{ $first->id ?? '' }}" />
当您提交包含所有其他字段的下一个表单时,您也会获得隐藏的 ID。所以再次在你的控制器方法中你会做类似
的事情FirstForm::where('id',request('update_id'))->update([
//here goes your other fields of the nextform
]);