예제 #1
0
 /**
  * Execute the job.
  *
  * @return bool
  */
 public function handle()
 {
     $this->category->name = $this->request->input('name');
     $this->category->options = ['manager' => $this->request->has('manager')];
     $this->category->parent_id = $this->request->parent;
     return $this->category->save();
 }
 /**
  * Creates a new Category model.
  * For ajax request will return json object
  * and for non-ajax request if creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $request = Yii::$app->request;
     $model = new Category();
     if ($request->isAjax) {
         /*
          *   Process for ajax request
          */
         Yii::$app->response->format = Response::FORMAT_JSON;
         if ($request->isGet) {
             return ['title' => "Create new Category", 'content' => $this->renderAjax('create', ['model' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])];
         } else {
             if ($model->load($request->post()) && $model->save()) {
                 return ['forceReload' => '#crud-datatable-pjax', 'title' => "Create new Category", 'content' => '<span class="text-success">Create Category success</span>', 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::a('Create More', ['create'], ['class' => 'btn btn-primary', 'role' => 'modal-remote'])];
             } else {
                 return ['title' => "Create new Category", 'content' => $this->renderAjax('create', ['model' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])];
             }
         }
     } else {
         /*
          *   Process for non-ajax request
          */
         if ($model->load($request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     }
 }
예제 #3
0
 public function create()
 {
     $category = new Category();
     if (Request::isMethod('post')) {
         $rules = array('name' => 'required', 'description' => 'required');
         $validator = Validator::make(Input::all(), $rules);
         if ($validator->fails()) {
             return Redirect::to('admin/category/create/')->withErrors($validator)->withInput();
         } else {
             if (empty(Input::get('seo_url'))) {
                 $seo_url = Helper::seo_url(Input::get('name'));
             } else {
                 $seo_url = Input::get('seo_url');
             }
             // store
             $category->name = Input::get('name');
             $category->description = Input::get('description');
             $category->seo_url = $seo_url;
             $category->save();
             $directory = $seo_url . '/' . $category->id;
             $tmpFilePath = Config::get('constants.IMAGES_ABSOLUTE_URL') . 'categories/' . $directory . '/';
             $file = Input::file('file');
             if ($file) {
                 $tmpFileName = time() . '-' . $file->getClientOriginalName();
                 $file->move($tmpFilePath, $tmpFileName);
                 $category->thumbnail = $directory . '/' . $tmpFileName;
                 $category->save();
             }
             Session::flash('message', 'Successfully created Category');
             return Redirect::to('/admin/category');
         }
     }
     return view('Admin.category.create')->with(['category' => $category])->withInput(Input::all());
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['cat_name' => 'required|unique:categories|max:255']);
     $cat = new Category();
     $cat->cat_name = $request->input('cat_name');
     //$post->slug = Str::slug(Input::get('title'));
     $cat->parent_id = Input::get('parent_id');
     $cat->cat_brief = Input::get('cat_brief');
     if ($file = Input::file('image')) {
         $allowed_extensions = ["png", "jpg", "gif"];
         if ($file->getClientOriginalExtension() && !in_array($file->getClientOriginalExtension(), $allowed_extensions)) {
             return ['error' => 'You may only upload png, jpg or gif.'];
         }
         $fileName = $file->getClientOriginalName();
         $extension = $file->getClientOriginalExtension() ?: 'png';
         $folderName = 'uploads/images/' . date("Ym", time()) . '/' . date("d", time());
         $destinationPath = public_path() . '/' . $folderName;
         $safeName = str_random(10) . '.' . $extension;
         $file->move($destinationPath, $safeName);
         $cat->image = $folderName . '/' . $safeName;
     }
     if ($cat->save()) {
         return Redirect::to('admin/goods/cats');
     } else {
         return Redirect::back()->withInput()->withErrors('保存失败!');
     }
 }
예제 #5
0
 public function actionSave($id = 0)
 {
     $form = new \app\models\CategoryForm();
     $post = Yii::$app->request->post();
     if ($form->load($post) && $form->validate()) {
         if ($id > 0) {
             $cat_current = Category::findOne($id);
             if (!$cat_current) {
                 throw new HttpException(404, 'Указанный Вами каталог не найден');
             }
         } else {
             $cat_current = new Category();
         }
         $parent_id = intval($post['CategoryForm']['parent_id']);
         if ($parent_id <= 0) {
             $depth = 1;
         } else {
             $parent_cat = Category::findOne($parent_id);
             $depth = intval($parent_cat->depth) + 1;
         }
         $cat_current->name = trim(htmlspecialchars($post['CategoryForm']['name']));
         $cat_current->parent_id = $parent_id;
         $cat_current->depth = $depth;
         $cat_current->save();
         return $this->redirect(Url::To(['category/cat', 'id' => $parent_id]));
     }
     return $this->redirect(Url::To(['category/' . ($id > 0 ? 'update' : 'add'), 'id' => $id]));
 }
예제 #6
0
파일: Store.php 프로젝트: stevebauman/ithub
 /**
  * Execute the job.
  *
  * @return bool
  */
 public function handle()
 {
     $this->category->name = $this->request->input('name');
     $this->category->belongs_to = 'inquiries';
     $this->category->options = ['manager' => $this->request->has('manager')];
     if ($this->request->has('parent')) {
         $this->category->parent_id = $this->request->input('parent');
     }
     if ($this->category->save()) {
         if ($this->parent instanceof Category) {
             $this->category->parent()->associate($this->parent);
         }
         return true;
     }
     return false;
 }
예제 #7
0
 public function store($request)
 {
     $category = new Category();
     $category->fill($request);
     $category->save();
     return $category;
 }
예제 #8
0
 /**
  * Create page
  *
  * @param Request $request
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
  */
 public function create(Request $request)
 {
     if ($request->isMethod('post')) {
         $rules = ['name' => 'required|unique:categories,name', 'alias' => 'required|unique:categories,alias', 'content' => 'required'];
         Validator::make($request->all(), $rules)->validate();
         $page = new Category();
         $page->name = $request->input('name');
         $page->alias = $request->input('alias');
         $page->meta_keys = $request->input('meta_keys');
         $page->meta_desc = $request->input('meta_desc');
         if ($request->has('parent')) {
             $page->parent_id = $request->input('parent');
             $page->type = 2;
         } else {
             $page->type = 1;
         }
         $page->content_type = 2;
         $page->publish = $request->has('publish');
         $page->save();
         $page_content = new PageContent();
         $page_content->content = $request->input('content');
         $page_content->page_id = $page->id;
         $page_content->save();
         return redirect()->route('pages');
     } else {
         $pages = Category::getParentCategories();
         return view('admin.page.create', compact('pages'));
     }
 }
예제 #9
0
 /**
  *
  * @param Request $request
  * @return Response
  */
 public function store(StoreCategoryRequest $request)
 {
     $category = new Category($request->only(['name']));
     $category->user()->associate(Auth::user());
     $category->save();
     return response($category->transform(), Response::HTTP_CREATED);
 }
예제 #10
0
 public function prosesAdd()
 {
     $cat = new Category();
     $cat->CategoryName = $_POST['name'];
     $cat->save();
     header("Location: " . base . "/Category");
 }
예제 #11
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     /*Default Category*/
     $category = new Category();
     $category->user_id = 0;
     $category->name = "Food & Drink";
     $category->save();
     $category = new Category();
     $category->user_id = 0;
     $category->name = "Bills";
     $category->save();
     $category = new Category();
     $category->user_id = 0;
     $category->name = "Transportation";
     $category->save();
     $category = new Category();
     $category->user_id = 0;
     $category->name = "Cellular";
     $category->save();
     $category = new Category();
     $category->user_id = 0;
     $category->name = "Tax";
     $category->save();
     $admin = new Admin();
     $admin->username = "******";
     $admin->password = "******";
     $admin->secret = "123456";
     $admin->save();
 }
예제 #12
0
 public static function addCategory($title, $mid)
 {
     $category = new Category();
     $category->title = $title;
     $category->mid = $mid;
     $category->sort_id = 1;
     $category->save();
 }
예제 #13
0
 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Category();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->ID]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
예제 #14
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int $id
  * @return Response
  */
 public function update(Category $categories, CategoryRequest $request)
 {
     $attachment = ImageUploadFacade::image($request->file('attachment'));
     $categories->fill($request->all());
     if ($attachment) {
         $categories->attachment()->associate($attachment);
     }
     $categories->save();
     return redirect()->route('admin.categories.index');
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $input = Input::all();
     $restaurant = Restaurant::where('user_id', Auth::user()->id)->first();
     $category = new Category();
     $category->restaurant_id = $restaurant->id;
     $category->category = $input['nombreCategoria'];
     $category->save();
     return redirect('admin/categories');
 }
예제 #16
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Category::truncate();
     $categoryNames = ['coding', 'social', 'faith', 'health', 'minimalism'];
     foreach ($categoryNames as $name) {
         $category = new Category(['name' => $name]);
         $category->user()->associate(User::first());
         $category->save();
     }
 }
예제 #17
0
 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Category();
     $categories = Category::find()->all();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', array('model' => $model, 'categories' => $categories));
     }
 }
예제 #18
0
public function postSave()
{
$category = new Category;
$category->user_id = $this->user->id;
$category->name = Input::get('name');
$category->description = Input::get('description');
$category->save();
return redirect('category')
->with('message', 'категория добавлена');
}
예제 #19
0
 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Category();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->setFlash('success', "Category <strong>{$model->title}</strong> created.");
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
예제 #20
0
 public function actionCreate()
 {
     $model = new Category();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['list']);
     } else {
         $model->status = Category::STATUS_ENABLED;
         return $this->render('create', ['model' => $model]);
     }
 }
예제 #21
0
 public function actionNew()
 {
     $categoryModel = new Category();
     $message = '';
     if (!empty(Yii::$app->request->post('Category'))) {
         if ($categoryModel->load(Yii::$app->request->post()) && $categoryModel->save()) {
             $message = 'Category added success';
         }
     }
     return $this->render('new', ['model' => $categoryModel, 'message' => $message]);
 }
 public function actionCreate()
 {
     $model = new Category();
     $model->user_id = Yii::$app->user->identity->id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->setFlash("Category-success", Yii::t("app", "Category successfully included"));
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
예제 #23
0
 public function actionCreatecategory()
 {
     $name = Yii::$app->request->post('name');
     $category = Yii::$app->request->post('category');
     Yii::$app->response->format = Response::FORMAT_JSON;
     $cat = new Category();
     $cat->name = $name;
     $cat->subcategory = $category;
     $cat->save();
     return $cat->id;
 }
예제 #24
0
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create()
 {
     if (!$this->checkLogin()) {
         return redirect('login');
     }
     $cat = new Category();
     $cat->catName = Request::input('catName');
     if ($cat->catName != null) {
         $cat->save();
     }
     return redirect('category');
 }
예제 #25
0
 public function postCreate()
 {
     $validator = Validator::make(Input::all(), Category::$rules);
     if ($validator->passes()) {
         $category = new Category();
         $category->name = Input::get('name');
         $category->parent_id = Input::get('parent_id');
         $category->save();
         return Redirect::to("admin/categories/edit/{$category->id}")->with('message', 'Категория создана');
     }
     return Redirect::back()->with('message', 'Ошибка сохранения')->withErrors($validator)->withInput();
 }
예제 #26
0
 public function create()
 {
     $data = Request::only('name');
     //$rules = ['name' => 'requried|max:255'];
     //need validate
     if (true) {
         $model = new Category($data);
         $model->save();
         return Redirect::back()->withResult('create succeed');
     } else {
         return Redirect::back()->withResult('create failed');
     }
 }
예제 #27
0
 public function postCategory(Request $req)
 {
     $rules = ['category_name' => ['required', 'min:2']];
     $valid = Validator::make($req->input(), $rules);
     if (!$valid->fails()) {
         $cat = new Category();
         $cat->category_name = $req->input('category_name');
         $cat->category_alias = strtolower(str_slug($req->input('category_name')));
         if ($cat->save()) {
             return redirect()->back()->with('msg', 'Successfully Saved Category');
         }
     } else {
         return redirect()->back()->withErrors($valid->errors());
     }
 }
예제 #28
0
 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->can('categoryCreate')) {
         $model = new Category();
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         if (Yii::$app->user->isGuest) {
             Yii::$app->user->loginRequired();
         } else {
             throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
         }
     }
 }
예제 #29
0
 public function createCategory($cat)
 {
     $category = Category::findOne(['name' => $cat]);
     if ($category == null) {
         $cat_row = new Category();
         $cat_row->name = $cat;
         if ($cat_row->save()) {
             //echo \yii\helpers\Json::encode($cat_row);
             $cat = $cat_row->id;
         } else {
             echo 'failed to create row';
             //echo $logo->errors();
         }
     } else {
         $cat = $category->id;
     }
     return $cat;
 }
예제 #30
0
 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->can("category/create")) {
         $model = new Category();
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             if ($model->parent == NULL) {
                 $model->parent = 0;
                 $model->save();
             }
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         Yii::$app->session->setFlash('error', 'Нет доступа!');
         $this->redirect('/');
     }
 }