public function getIndex() { $slide = new slideshow(); $data = $slide->select('slideshow.*', DB::raw("(case when page=0 then 'Trang Chu' else (select name from category where slideshow.page=category.id) end) as namepage"))->orderBy('id', 'desc')->get(); $datac = category::get(); return view("admin.slide.index", array('data' => $data, 'datac' => $datac)); }
public static function getCategoryWhereName($name) { $category = category::orderBy('id', 'desc')->get(); $convert = new convertString(); foreach ($category as $values) { if ($convert->convertString($values->name) == $name) { return $values->id; } } return 0; }
public function delete() { $product = product::where('categoryID', Input::get('id'))->get(); if (count($product) > 0) { if (Input::exists('json')) { return json_encode(array('result' => -1, 'message' => 'Loại sản phẩm "' . Input::get('title') . '" đã có sản phẩm. Không thể xóa')); } return Redirect::to('admin/category')->with(['message' => 'Loại sản phẩm "' . Input::get('title') . '" đã có sản phẩm. Không thể xóa']); } $category = category::find(Input::get('id')); if ($category->delete()) { if (Input::exists('json')) { return json_encode(array('result' => 1)); } return Redirect::to('admin/category')->with(['message' => 'Xóa thành công loại sản phẩm "' . Input::get('title') . '"']); } else { if (Input::exists('json')) { return json_encode(array('result' => -1, 'message' => 'Có lỗi. Xóa thất bại')); } return Redirect::to('admin/category')->with(['message' => 'Loại sản phẩm "' . Input::get('title') . '" đã có sản phẩm. Không thể xóa']); } }
public function edit() { if (!Input::exists('id')) { return Redirect::to('admin/product')->with(['message' => 'Vui lòng chọn 1 sản phẩm để sửa.']); } $data = array(); $data['data'] = product::where('id', Input::get('id'))->first(); if ($data['data'] == null) { return Redirect::to('admin/product')->with(['message' => 'Sản phẩm không tồn tại.']); } $data['datamenu'] = menu::select('id', 'name', 'root')->where('url', '')->get(); $data['datacategory'] = category::select('id', 'name')->get(); $data['datatabcategory'] = tab_category::select('id', 'name')->get(); $data['detail'] = detailproduct::where('productID', Input::get('id'))->first(); return View::make("admin.product.edit", $data); }