public function store(Request $request)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess('Tags', 'create')) {
            return $this->noPermission();
        }

        $validatorData = [
            'title' => 'required',
            'postTypeID' => 'required',
            'slug' => 'required|max:500|unique:tags',
        ];

        if(isset($request->formData['id'])) {
            // Update Tag
            $tags = Tag::findOrFail($request->formData['id']);
            $validatorData['slug'] = 'required';
        }else{
            $tags = new Tag();
            $tags->createdByUserID = Auth::user()->userID;
            $tags->postTypeID = $request->formData['postTypeID'];
        }

        // validation
        $validator = Validator::make($request->formData, $validatorData, []);
        // check validation
        if ($validator->fails()) {
            return $this->response("Please check all required fields!", 400, null, false, false, true, $validator->errors());
        }

        $tags->title         = $request->formData['title'];
        $tags->description   = $request->formData['description'];
        $tags->slug          = $request->formData['slug'];
        $tags->featuredImageID = ($request->formData['featuredImage']  !== 0 ? $request->formData['featuredImage'] : null);

        // return results
        if ($tags->save()) {
            $redirect = $this->redirect($request->formData['redirect'], $tags->tagID, $request->formData['postTypeID']);
            $result = $this->response('Tag is saved', 200, $redirect['id'], $redirect['view'], $redirect['url']);
        }else{
            $result = $this->response('Internal server error. Please try again later', 500);
        }
        return $result;
    }
public function store(Request $request)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess('Tags', 'create')) {
            return $this->noPermission();
        }

        $validatorData = [
            'title' => 'required',
            'postTypeID' => 'required',
            'slug' => 'required|max:500|unique:tags',
        ];

        if(isset($request->formData['id'])) {
            // Update Tag
            $tags = Tag::findOrFail($request->formData['id']);
            $validatorData['slug'] = 'required';
        }else{
            $tags = new Tag();
            $tags->createdByUserID = Auth::user()->userID;
            $tags->postTypeID = $request->formData['postTypeID'];
        }

        // validation
        $validator = Validator::make($request->formData, $validatorData, []);
        // check validation
        if ($validator->fails()) {
            return $this->response("Please check all required fields!", 400, null, false, false, true, $validator->errors());
        }

        $tags->title         = $request->formData['title'];
        $tags->description   = $request->formData['description'];
        $tags->slug          = $request->formData['slug'];
        $tags->featuredImageID = ($request->formData['featuredImage']  !== 0 ? $request->formData['featuredImage'] : null);

        // return results
        if ($tags->save()) {
            $redirect = $this->redirect($request->formData['redirect'], $tags->tagID, $request->formData['postTypeID']);
            $result = $this->response('Tag is saved', 200, $redirect['id'], $redirect['view'], $redirect['url']);
        }else{
            $result = $this->response('Internal server error. Please try again later', 500);
        }
        return $result;
    }
public function store ( Request $ request ) { // check if user has permissions to access this link if ( ! User :: hasAccess ( 'Tags' , 'create' ) ) { return $ this -> noPermission ( ) ; } $ validatorData = [ 'title' => 'required' , 'postTypeID' => 'required' , 'slug' => 'required|max:500|unique:tags' , ] ; if ( isset ( $ request -> formData [ 'id' ] ) ) { // Update Tag $ tags = Tag :: findOrFail ( $ request -> formData [ 'id' ] ) ; $ validatorData [ 'slug' ] = 'required' ; } else { $ tags = new Tag ( ) ; $ tags -> createdByUserID = Auth :: user ( ) -> userID ; $ tags -> postTypeID = $ request -> formData [ 'postTypeID' ] ; } // validation $ validator = Validator :: make ( $ request -> formData , $ validatorData , [ ] ) ; // check validation if ( $ validator -> fails ( ) ) { return $ this -> response ( "Please check all required fields!" , 400 , null , false , false , true , $ validator -> errors ( ) ) ; } $ tags -> title = $ request -> formData [ 'title' ] ; $ tags -> description = $ request -> formData [ 'description' ] ; $ tags -> slug = $ request -> formData [ 'slug' ] ; $ tags -> featuredImageID = ( $ request -> formData [ 'featuredImage' ] !== 0 ? $ request -> formData [ 'featuredImage' ] : null ) ; // return results if ( $ tags -> save ( ) ) { $ redirect = $ this -> redirect ( $ request -> formData [ 'redirect' ] , $ tags -> tagID , $ request -> formData [ 'postTypeID' ] ) ; $ result = $ this -> response ( 'Tag is saved' , 200 , $ redirect [ 'id' ] , $ redirect [ 'view' ] , $ redirect [ 'url' ] ) ; } else { $ result = $ this -> response ( 'Internal server error. Please try again later' , 500 ) ; } return $ result ; }
Store a new tag in database.

@param  Request $request
@return array
Store a new tag in database .