public function archive($publicId) { $category = Category::scope($publicId)->firstOrFail(); $category->delete(); Session::flash('message', trans('texts.archived_category')); return Redirect::to('company/categories'); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function bulk() { $public_id = Input::get('public_id'); $category = Category::scope($public_id)->first(); $getProductCount = Product::scope()->where('category_id', '=', $category->id)->count(); // return Response::json($getProductCount); if ($getProductCount > 0) { $field = $getProductCount == 1 ? ' ' : 's'; $field2 = $getProductCount == 1 ? ' pertenece' : ' pertenecen'; $message = $getProductCount . " Producto" . $field . $field2 . " a la categoría " . $category->name; Session::flash('error', $message); return Redirect::to('categorias'); } else { $category->delete(); $message = "Categoría eliminada con éxito"; Session::flash('message', $message); return Redirect::to('categorias'); } }