Laravel controller code:
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
]);
}
This is my function to add the values for one of the forms.
controller code for second form:
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);
}
This is my another function for adding another form values. But here I am using product_Id value is a foreign key value and I need to get this with before added form.I don't know how to get this. Or else it is helpful if I pass both the form values in a single function.
Script Code:
<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>