public function getPriceList($depoID, ProductCart $productCart) { $depo = Stantion::with('price.product.category')->where('id', $depoID)->first(); $categoriesArr = []; if (Auth::guest()) { $userID = 0; } else { $userID = Auth::user()->id; } foreach ($depo->price as $price) { if ($price->product[0]->category) { $key = $price->product[0]->category->category; } else { $key = 'Прочие товары'; } if ($price->price > 0 && $price->amount > 0) { $categoriesArr[$key][] = ['name' => $price->product[0]->name, 'product_id' => $price->product[0]->id, 'depo_id' => $depo->id, 'price_id' => $price->id, 'article' => $price->product[0]->article, 'description' => $price->product[0]->description, 'price' => $price->price, 'amount' => $price->amount]; } } $sumAndCount = $this->getGeneralViewOfCart($productCart); return view('purchases.trainCarPriceList', ['p' => 'purchases', 'categoriesArr' => $categoriesArr, 'depoName' => $depo->stantion_name, 'depoId' => $depoID, 'userID' => $userID, 'productsCount' => $sumAndCount['productsCount'], 'productsSum' => $sumAndCount['productsSum']]); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { //$station = Stantion::find($id); $station = Stantion::with(['price'])->where('id', $id)->first(); DB::transaction(function () use($station) { $station->price()->detach(); foreach ($station->price as $price) { $price->delete(); } $station->delete(); }); //Region::destroy($id); return back()->with('alert-success', 'Станция ' . $station->stantion_name . ' удалена'); }