/**
  * API or removing materials being called from js
  */
 public function removeSubProduct(Request $request)
 {
     $prodId = $request->input('product_id');
     $subProdId = $request->input('sub_product_id');
     //delete sub product
     MainSubProduct::where('product_id', $prodId)->where('sub_product_id', $subProdId)->delete();
     //get all subproducts associated
     $curSubProducts = array();
     $curSubProductIds = array();
     $subProducts = Product::find($prodId)->sub_products()->get();
     foreach ($subProducts as $pm) {
         //gets the current set materials
         $subprodExtObject = SubProduct::where('is_active', true)->where('id', $pm->sub_product_id)->first();
         array_push($curSubProducts, $subprodExtObject);
         array_push($curSubProductIds, $pm->sub_product_id);
         $subprodExtObject = null;
     }
     //get all the subproducts not in current main product
     $allSubProducts = SubProduct::whereNotIn('id', $curSubProductIds)->orderBy('sub_product_name', 'asc')->get();
     //return current and all materials
     return json_encode(array('curSubProducts' => $curSubProducts, 'allSubProducts' => $allSubProducts));
 }
 /**
  * API or adding materials being called from js
  */
 public function removeMaterial(Request $request)
 {
     $prodId = $request->input('sub_product_id');
     $matId = $request->input('material_id');
     //delete material product
     SubProductMaterial::where('sub_product_id', $prodId)->where('material_id', $matId)->delete();
     //get the product-materials
     $curMaterials = array();
     $curMatIds = array();
     $prodMaterials = SubProduct::find($prodId)->materials()->get();
     foreach ($prodMaterials as $pm) {
         //gets the current set materials
         $matExtObject = Material::where('is_active', true)->where('id', $pm->material_id)->first();
         array_push($curMaterials, $matExtObject);
         array_push($curMatIds, $pm->material_id);
     }
     //get the all current materials
     $allMaterials = Material::whereNotIn('id', $curMatIds)->where('is_active', True)->orderBy('material_name', 'asc')->get();
     //return current and all materials
     return json_encode(array('curMaterials' => $curMaterials, 'allMaterials' => $allMaterials));
 }