public function create_category(Request $request) { $rules = array('category' => 'required'); $validator = Validator::make($request->all(), $rules); if (!$validator->fails()) { $value = strtolower($request->category); $db_cat = Category::where('name', $value)->first(); if ($db_cat) { return redirect('master/setting/category/list')->with('failed', 'Maaf kategori telah tersedia'); } else { $category = new Category(); $category->name = $value; $category->slug = str_replace(" ", "-", $value); $category->save(); return redirect('master/setting/category/list')->with('success', 'Kategori baru berhasil ditambahkan'); } } else { return redirect('master/setting/category/list')->with('failed', 'Silahkan isi Nama Kategori'); } }
public function add_category(Request $request) { $rules = array('name' => 'required', 'slug' => 'required'); $validator = Validator::make($request->all(), $rules); if (!$validator->fails()) { $category = new Category(); $category->name = $request->input('name'); $category->slug = $request->input('slug'); $category->save(); return redirect('master/category/list'); } else { return redirect('master/category/create')->with('error', 'Terdapat form kosong'); } }