original_string: public function categoriesAdd(Request $request, Response $response)
      {
          if ($check = $this->sentinel->hasPerm('blog_categories.create', 'dashboard', $this->config['blog-enabled'])) {
              return $check;
          }
  
          if ($request->isPost()) {
              $this->validator->validate($request, [
                  'category_name' => V::length(2, 25)->alpha('\''),
                  'category_slug' => V::slug()
              ]);
  
              $checkSlug = BC::where('slug', '=', $request->getParam('category_slug'))->get()->count();
  
              if ($checkSlug > 0) {
                  $this->validator->addError('category_slug', 'Slug already in use.');
              }
  
              if ($this->validator->isValid()) {
                  $addCategory = new BC;
                  $addCategory->name = $request->getParam('category_name');
                  $addCategory->slug = $request->getParam('category_slug');
  
                  if ($addCategory->save()) {
                      $this->flash('success', 'Category added successfully.');
                      return $this->redirect($response, 'admin-blog');
                  }
              }
              $this->flash('danger', 'An error occured while adding this category.');
          }
  
          return $this->redirect($response, 'admin-blog');
      }
code: public function categoriesAdd(Request $request, Response $response)
      {
          if ($check = $this->sentinel->hasPerm('blog_categories.create', 'dashboard', $this->config['blog-enabled'])) {
              return $check;
          }
  
          if ($request->isPost()) {
              $this->validator->validate($request, [
                  'category_name' => V::length(2, 25)->alpha('\''),
                  'category_slug' => V::slug()
              ]);
  
              $checkSlug = BC::where('slug', '=', $request->getParam('category_slug'))->get()->count();
  
              if ($checkSlug > 0) {
                  $this->validator->addError('category_slug', 'Slug already in use.');
              }
  
              if ($this->validator->isValid()) {
                  $addCategory = new BC;
                  $addCategory->name = $request->getParam('category_name');
                  $addCategory->slug = $request->getParam('category_slug');
  
                  if ($addCategory->save()) {
                      $this->flash('success', 'Category added successfully.');
                      return $this->redirect($response, 'admin-blog');
                  }
              }
              $this->flash('danger', 'An error occured while adding this category.');
          }
  
          return $this->redirect($response, 'admin-blog');
      }
code_tokens: public function categoriesAdd ( Request $ request , Response $ response ) { if ( $ check = $ this -> sentinel -> hasPerm ( 'blog_categories.create' , 'dashboard' , $ this -> config [ 'blog-enabled' ] ) ) { return $ check ; } if ( $ request -> isPost ( ) ) { $ this -> validator -> validate ( $ request , [ 'category_name' => V :: length ( 2 , 25 ) -> alpha ( '\'' ) , 'category_slug' => V :: slug ( ) ] ) ; $ checkSlug = BC :: where ( 'slug' , '=' , $ request -> getParam ( 'category_slug' ) ) -> get ( ) -> count ( ) ; if ( $ checkSlug > 0 ) { $ this -> validator -> addError ( 'category_slug' , 'Slug already in use.' ) ; } if ( $ this -> validator -> isValid ( ) ) { $ addCategory = new BC ; $ addCategory -> name = $ request -> getParam ( 'category_name' ) ; $ addCategory -> slug = $ request -> getParam ( 'category_slug' ) ; if ( $ addCategory -> save ( ) ) { $ this -> flash ( 'success' , 'Category added successfully.' ) ; return $ this -> redirect ( $ response , 'admin-blog' ) ; } } $ this -> flash ( 'danger' , 'An error occured while adding this category.' ) ; } return $ this -> redirect ( $ response , 'admin-blog' ) ; }
docstring: Add New Blog Category
docstring_tokens: Add New Blog Category