两个表中的Instert数据与Laravel的关系
我想用一个表单插入到两个与外键相关的表中 首先,您需要使用customername创建订单,然后将订单转发到下一个表单以插入多个项目 我的桌子是这样制作的:两个表中的Instert数据与Laravel的关系,laravel,forms,insert,Laravel,Forms,Insert,我想用一个表单插入到两个与外键相关的表中 首先,您需要使用customername创建订单,然后将订单转发到下一个表单以插入多个项目 我的桌子是这样制作的: Schema::create('returnorders', function (Blueprint $table) { $table->increments('id'); $table->string('firmaname'); $table->st
Schema::create('returnorders', function (Blueprint $table) {
$table->increments('id');
$table->string('firmaname');
$table->string('contacperson');
$table->string('email')->unique();
$table->string('ordernumber');
$table->string('customername');
$table->timestamps();
});
Schema::create('returnarticles', function (Blueprint $table) {
$table->increments('id');
$table->integer('order_id')->unsigned();
$table->foreign('order_id')->references('id')->on('returnorders');
$table->string('articlenumber');
$table->string('return_quantity');
$table->string('return_quality');
$table->string('return_reason');
$table->string('images');
});
我现在的问题是,我可以制作一个表格,在其中放置多篇文章,还是制作两个表格,然后将您从第一个表格转发到下一个表格
我的第二个问题是,我可以在控制器中的一个函数中执行此操作,还是应该执行两个函数
请帮帮我,如果可能的话,告诉我如何使用我的功能
谢谢如果您的问题是如何保存这些相关模型,那么您应该查看有关插入和更新相关模型的文档: 您的代码可能如下所示:
$returnOrder = ReturnOrder::create([
'firmaname' => $validatedInput['firmaname'],
'contactperson' => $validatedInput['contactperson'],
....
]);
$returnOrder->returnArticles()->save(ReturnArticle::create([
'articlenumber' => $validatedInput['articleNumber'],
...
]));