gpt4 book ai didi

php - 如何将两种形式作为参数传递给 laravel Controller ?

转载 作者:行者123 更新时间:2023-11-28 23:11:28 25 4
gpt4 key购买 nike

Laravel Controller 代码:

public function addPriceDetails(Request $priceform,$dataId)
{
$priceInfo = new priceInfo ;
$priceInfo->deviceCategoryId=$dataId;
$priceInfo->productId=$this->getproductId();
$priceInfo->SKUID=$priceform->input('skuid');
$priceInfo->productName=$priceform->input('productName');
$priceInfo->listingStatus =$priceform->input('listingStatus');
$priceInfo->MRP =$priceform->input('mrp');
$priceInfo->sellingPrice=$priceform->input('selprice');
$priceInfo->fulfillmentBy =$priceform->input('fulfillment');
$priceInfo->procurementType =$priceform->input('procurementType');
$priceInfo->procurementSLA =$priceform->input('sla');
$priceInfo->stock =$priceform->input('stock');
$priceInfo->localDelCharge =$priceform->input('local');
$priceInfo->zonalDelCharge =$priceform->input('zonal');
$priceInfo->nationalDelCharge=$priceform->input('national');
$priceInfo->packWeight =$priceform->input('weight');
$priceInfo->packLength =$priceform->input('length');
$priceInfo->packBreadth =$priceform->input('breadth');
$priceInfo->packHeight =$priceform->input('height');
$priceInfo->HSN =$priceform->input('hsn');
$priceInfo->save();

return response()->json([
'SKUID' => $priceInfo->SKUID,
'listingStatus' => $priceInfo->listingStatus,
'MRP' => $priceInfo->MRP,
'sellingPrice' => $priceInfo->sellingPrice
]);
}

这是我为其中一种形式添加值的功能。

第二种形式的 Controller 代码:

  public function addProductDetails(Request $formdescription,$dataId)
{
$description=new productDescription;
$description->deviceCategoryId=$dataId;
$description->productDescriptionId=$this-
>getproductDescriptionId();
$description->modelName=$formdescription->input('mname');
$description->Height=$formdescription->input('height');
$description->Weight=$formdescription->input('weight');
$description->Depth=$formdescription->input('depth');
$description->Width =$formdescription->input('width');
$description->Type =$formdescription->input('type');
$description->Character=$formdescription->input('character');
$description->batteryType=$formdescription->input('batteryType');
$description->salesPackage =$formdescription->input('package');
$description->skillSet =$formdescription->input('skillSet');
$description->Colour=$formdescription->input('colour');
$description->Material =$formdescription->input('material');
$description->maxAge=$formdescription->input('maxage');
$description->minAge =$formdescription->input('minage');
$description->batteryNos =$formdescription->input('batteryNos');
$description->batteryOperated=$formdescription-
>input('batteryOperated');
$description->rechargable=$formdescription->input('rechargable');

$description->save();



return response()->json([
'modelName' => $formdescription->mname,
'colour' => $formdescription->colour,
'rechargable' => $formdescription->rechargable,
'batteryType' => $formdescription->batteryType
]);

$description->product()->associate($priceInfo);
}

这是我添加另一个表单值的另一个函数。但是我在这里使用的 product_Id 值是一个外键值,我需要在添加表单之前获取它。我不知道如何获取它。 否则如果我在单个函数中传递两个表单值。

脚本代码:

    <script src = 
"https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script type="text/javascript">

$(document).ready(function () {

$("#priceSave").click(function(e){
e.preventDefault();
var form1 = $('#priceform').serialize();
//alert(form1);
$.ajax({
url:'addPriceDetails/{{$dataId}}',
type: "get",
data: form1,
dataType: 'json',
success: function(response) {
//alert(response.SKUID);
$("#skuid").append(response.SKUID);
$("#mrp").append(response.MRP);
$("#lstatus").append(response.listingStatus);
$("#selprice").append(response.sellingPrice);
}
});
});



$("#descSave").click(function(e){
e.preventDefault();
var form2 = $('#formdescription').serialize();
alert(form2);
$.ajax({
url:'addProductDetails/{{$dataId}}',
type: "get",
data: form2,
dataType: 'json',
success: function(response) {
//alert(response);
$("#batterytype").append(response.batteryType);
$("#modelname").append(response.modelName);
$("#colour").append(response.colour);
// $("#colour").append(response.Colour);
$("#rechargable").append(response.rechargable);
//alert(response.Material);
//alert(response.salesPackage);
}
});
});


});
</script>

最佳答案

你应该试试这个:

return response()->json([
'SKUID' => $priceInfo->SKUID,
'listingStatus' => $priceInfo->listingStatus,
'MRP' => $priceInfo->MRP,
'sellingPrice' => $priceInfo->sellingPrice,
'id' =>$this->getproductId()
]);

关于php - 如何将两种形式作为参数传递给 laravel Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45791192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com