/**
  * API or removing materials being called from js
  */
 public function removeMaterial(Request $request)
 {
     $prodId = $request->input('product_id');
     $matId = $request->input('material_id');
     //delete material product
     ProductMaterial::where('product_id', $prodId)->where('material_id', $matId)->delete();
     //get the product-materials
     $curMaterials = array();
     $curMatIds = array();
     $prodMaterials = Product::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));
 }
 public function materialsAllAPI()
 {
     $materials = Material::all();
     return json_encode($materials);
 }