示例#1
0
 public function postForm(FormCategoryRequest $request)
 {
     if (!empty($request)) {
         $pathImage = $request->get('picture', null);
         $data = $request->all();
         if ($request->hasfile('picture')) {
             $validator = Validator::make($request->all(), ['picture' => ['mimes:jpg,png,jpeg']]);
             if ($validator->fails()) {
                 return redirect(action('Admin\\CategoryController@postForm'))->withErrors($validator)->withInput();
             }
             $file = $request->file('picture');
             $nameimage = date('Ymdhis') . rand(1, 1000) . '.' . $file->getClientOriginalExtension();
             $file->move(public_path() . "/dinamic/category/", $nameimage);
             $pathImage = '/dinamic/category/' . $nameimage;
             $data['picture'] = $pathImage;
         }
         $data['flagactive'] = $request->get('flagactive', 1);
         if ($request->id) {
             $obj = Categories::find($request->id);
             $obj->update($data);
             $idTips = $obj->id;
         } else {
             $obj = Categories::create($data);
             $idTips = $obj->id;
         }
         return redirect('admpanel/' . self::NAMEC)->with('messageSuccess', 'Caracteristicas Guardado');
     }
     return redirect('admpanel')->with('messageError', 'Error al guardar el tip');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $categories = ['shoujitongxun' => ['display_name' => '手机通讯', 'sub' => [['zhinengshouji', '智能手机'], ['feizhinengshouji', '非智能手机'], ['duijiangji', '对讲机'], ['lanyaerji', '蓝牙耳机']]], 'sheyingshexiang' => ['display_name' => '摄影摄像', 'sub' => [['danfangjisheng', '单反机身'], ['weidanxiangji', '微单相机'], ['shumaxiangji', '数码相机'], ['jiayongshexiangji', '家用摄像机'], ['zhuanyeshexiangji', '专业摄像机']]], 'xiangjipeijian' => ['display_name' => '相机配件', 'sub' => [['shumapeijian', '数码配件'], ['chongdianqi', '充电器'], ['dianchi', '电池'], ['diannaozhijia', '电脑支架'], ['yidongdianyuan', '移动电源'], ['chukongbi', '触控笔'], ['qitashumapeijian', '其它数码配件']]]];
     foreach ($categories as $name => $category) {
         $parent = Categories::create(['slug' => $name, 'name' => $category['display_name'], 'parent_id' => -1]);
         $subs = $category['sub'];
         foreach ($subs as $sub_category) {
             Categories::create(['slug' => $sub_category[0], 'name' => $sub_category[1], 'parent_id' => $parent->id]);
         }
     }
 }
 public function store($request)
 {
     $cacheTag = ['categories'];
     $validator = $this->validate($request);
     if (!$validator->fails()) {
         Logs::create(['activity' => 'store', 'module' => 'categories']);
         Cache::tags($cacheTag)->flush();
         $request['company_id'] = config('global.companies.current.id');
         return Categories::create($request);
     } else {
         return new \Exception($validator->errors()->first());
     }
 }
 public function create()
 {
     if (Request::isMethod('get')) {
         $data['page_title'] = 'Data Kategori';
         return view('categories.create', $data);
     } else {
         if (Request::isMethod('post')) {
             $nama = Input::get('nama');
             $kode = Input::get('kode');
             $item = array('name' => $nama);
             Categories::create($item);
             return redirect('categories');
         }
     }
 }
示例#5
0
 public function store()
 {
     $name = Input::has("name") ? Input::get("name") : "";
     $lang = Input::get("lang");
     $name_lang = Input::has("name_lang") ? Input::get("name_lang") : "";
     if ($name == "") {
         Session::flash("error", trans("categories.notifications.field_name_missing"));
         return Redirect::to("/categories/create")->withInput();
     }
     $category_id = Categories::create(array('name' => $name));
     //dd($lang, $name_lang,$category_id->id ); exit;
     if ($lang != "en" && $name_lang != " ") {
         AppCategoriesI18n::create(array('category_id' => $category_id->id, 'lang' => $lang, 'name' => $name_lang));
     }
     Session::flash('success', trans("categories.notifications.register_successful"));
     return Redirect::to("/categories");
 }
 public static function add()
 {
     if (!Request::is_admin()) {
         Response::redirect('');
     }
     if ("POST" == Request::method()) {
         $id_acc = Request::user()->id;
         $name = Request::POST()->name;
         $decsription = Request::POST()->description;
         Categories::create($id_acc, $name, $decsription);
         # push flash-message
         Session::push('flash-message', 'That category has successfuly added!');
         Response::redirect('categories');
     } else {
         $categories = Categories::all()->fetchAll(\PDO::FETCH_CLASS);
         View::render('categories/add', ['categories' => $categories]);
     }
 }
 public function newCategory($id)
 {
     if ($_POST) {
         $request = (object) $_POST;
         $category = new Categories();
         if (isset($id)) {
             $category->update($id, $request->nombre, $request->descripcion);
             newFlashMessage('test', 'Categoria ' . ucwords($request->nombre) . " actualizada.");
             return redirect('admin/category');
         } else {
             $category->create($request->nombre, $request->descripcion);
             newFlashMessage('test', 'Categoria ' . ucwords($request->nombre) . " creada.");
             return redirect('admin/category/');
         }
     } elseif (isset($id)) {
         $categories = new Categories();
         $category = $categories->find($id);
         return view('admin/categories/update', compact('category'), 'baseAdmin');
     } else {
         return view('admin/categories/create', '', 'baseAdmin');
     }
 }