public function categoriesEdit(Request $request, Response $response, $categoryId)
    {
        if ($check = $this->sentinel->hasPerm('blog_categories.update', 'dashboard', $this->config['blog-enabled'])) {
            return $check;
        }

        $category = BC::find($categoryId);

        if (!$category) {
            $this->flash('danger', 'Sorry, that category was not found.');
            return $response->withRedirect($this->router->pathFor('admin-blog'));
        }

        if ($request->isPost()) {
            // Get Vars
            $categoryName = $request->getParam('category_name');
            $categorySlug = $request->getParam('category_slug');

            // Validate Data
            $validateData = array(
                'category_name' => array(
                    'rules' => V::length(2, 25)->alpha('\''),
                    'messages' => array(
                        'length' => 'Must be between 2 and 25 characters.',
                        'alpha' => 'Letters only and can contain \''
                        )
                ),
                'category_slug' => array(
                    'rules' => V::slug(),
                    'messages' => array(
                        'slug' => 'May only contain lowercase letters, numbers and hyphens.'
                        )
                )
            );

            $this->validator->validate($request, $validateData);

            // Validate Category Slug
            $checkSlug = $category->where('id', '!=', $category->id)
                ->where('slug', '=', $categorySlug)
                ->get()
                ->count();
            if ($checkSlug > 0 && $categorySlug != $category->slug) {
                $this->validator->addError('category_slug', 'Category slug is already in use.');
            }


            if ($this->validator->isValid()) {
                if ($category->id == 1) {
                    $this->flash('danger', 'Cannot edit uncategorized category.');
                    return $this->redirect($response, 'admin-blog');
                }

                $category->name = $categoryName;
                $category->slug = $categorySlug;

                if ($category->save()) {
                    $this->flash('success', 'Category has been updated successfully.');
                    return $this->redirect($response, 'admin-blog');
                }
            }
            $this->flash('danger', 'An error occured updating the category.');
        }

        return $this->view->render($response, 'blog-categories-edit.twig', ['category' => $category]);
    }
public function categoriesEdit(Request $request, Response $response, $categoryId)
    {
        if ($check = $this->sentinel->hasPerm('blog_categories.update', 'dashboard', $this->config['blog-enabled'])) {
            return $check;
        }

        $category = BC::find($categoryId);

        if (!$category) {
            $this->flash('danger', 'Sorry, that category was not found.');
            return $response->withRedirect($this->router->pathFor('admin-blog'));
        }

        if ($request->isPost()) {
            // Get Vars
            $categoryName = $request->getParam('category_name');
            $categorySlug = $request->getParam('category_slug');

            // Validate Data
            $validateData = array(
                'category_name' => array(
                    'rules' => V::length(2, 25)->alpha('\''),
                    'messages' => array(
                        'length' => 'Must be between 2 and 25 characters.',
                        'alpha' => 'Letters only and can contain \''
                        )
                ),
                'category_slug' => array(
                    'rules' => V::slug(),
                    'messages' => array(
                        'slug' => 'May only contain lowercase letters, numbers and hyphens.'
                        )
                )
            );

            $this->validator->validate($request, $validateData);

            // Validate Category Slug
            $checkSlug = $category->where('id', '!=', $category->id)
                ->where('slug', '=', $categorySlug)
                ->get()
                ->count();
            if ($checkSlug > 0 && $categorySlug != $category->slug) {
                $this->validator->addError('category_slug', 'Category slug is already in use.');
            }


            if ($this->validator->isValid()) {
                if ($category->id == 1) {
                    $this->flash('danger', 'Cannot edit uncategorized category.');
                    return $this->redirect($response, 'admin-blog');
                }

                $category->name = $categoryName;
                $category->slug = $categorySlug;

                if ($category->save()) {
                    $this->flash('success', 'Category has been updated successfully.');
                    return $this->redirect($response, 'admin-blog');
                }
            }
            $this->flash('danger', 'An error occured updating the category.');
        }

        return $this->view->render($response, 'blog-categories-edit.twig', ['category' => $category]);
    }
public function categoriesEdit ( Request $ request , Response $ response , $ categoryId ) { if ( $ check = $ this -> sentinel -> hasPerm ( 'blog_categories.update' , 'dashboard' , $ this -> config [ 'blog-enabled' ] ) ) { return $ check ; } $ category = BC :: find ( $ categoryId ) ; if ( ! $ category ) { $ this -> flash ( 'danger' , 'Sorry, that category was not found.' ) ; return $ response -> withRedirect ( $ this -> router -> pathFor ( 'admin-blog' ) ) ; } if ( $ request -> isPost ( ) ) { // Get Vars $ categoryName = $ request -> getParam ( 'category_name' ) ; $ categorySlug = $ request -> getParam ( 'category_slug' ) ; // Validate Data $ validateData = array ( 'category_name' => array ( 'rules' => V :: length ( 2 , 25 ) -> alpha ( '\'' ) , 'messages' => array ( 'length' => 'Must be between 2 and 25 characters.' , 'alpha' => 'Letters only and can contain \'' ) ) , 'category_slug' => array ( 'rules' => V :: slug ( ) , 'messages' => array ( 'slug' => 'May only contain lowercase letters, numbers and hyphens.' ) ) ) ; $ this -> validator -> validate ( $ request , $ validateData ) ; // Validate Category Slug $ checkSlug = $ category -> where ( 'id' , '!=' , $ category -> id ) -> where ( 'slug' , '=' , $ categorySlug ) -> get ( ) -> count ( ) ; if ( $ checkSlug > 0 && $ categorySlug != $ category -> slug ) { $ this -> validator -> addError ( 'category_slug' , 'Category slug is already in use.' ) ; } if ( $ this -> validator -> isValid ( ) ) { if ( $ category -> id == 1 ) { $ this -> flash ( 'danger' , 'Cannot edit uncategorized category.' ) ; return $ this -> redirect ( $ response , 'admin-blog' ) ; } $ category -> name = $ categoryName ; $ category -> slug = $ categorySlug ; if ( $ category -> save ( ) ) { $ this -> flash ( 'success' , 'Category has been updated successfully.' ) ; return $ this -> redirect ( $ response , 'admin-blog' ) ; } } $ this -> flash ( 'danger' , 'An error occured updating the category.' ) ; } return $ this -> view -> render ( $ response , 'blog-categories-edit.twig' , [ 'category' => $ category ] ) ; }
Edit Blog Category
Edit Blog Category