示例#1
0
 public function getStocks($id)
 {
     $stocks = StockCount::where('product_id', '=', $id)->get();
     $stockArray = array();
     $x = "";
     foreach ($stocks as $row) {
         $stockInfo = StockInfo::find($row->stock_info_id);
         $x .= "<option value='" . $row->stock_info_id . "'>" . $stockInfo->name . " (" . $row->product_quantity . ")</option>";
         array_push($stockArray, $row->stock_info_id);
     }
     $stocks = StockInfo::whereNotIn('id', $stockArray)->get();
     foreach ($stocks as $row) {
         $x .= "<option value='" . $row->id . "'>" . $row->name . " (0)</option>";
     }
     $product = Product::find($id);
     $data = array('list' => $x, 'price' => $product->price);
     return json_encode($data);
 }