public function store(Request $request)
    {
        $data = $request->all();

        // check permissions
        if(isset($data['postID'])) {
            if(!User::hasAccess($request->postType, 'update', $data['postID'], true)) {
                return $this->noPermission();
            }
        }else{
            if(!User::hasAccess($request->postType, 'create')) {
                return $this->noPermission();
            }
        }

        $results = $this->fillEmptyTitles($data);
        $data = $results['data'];
        $firstFilledTitle = $results['firstFilledTitle'];

        // generate a unique slug
        $postID = 0;
        if(isset($data['postID'])) {
            $postID = $data['postID'];
        }

        $data['slug'] = $this->fillEmptySlugs($data['slug'], $data['postType'], $firstFilledTitle, $postID);

        try{
            $postResult = Post::store($data);

            if($postResult['error']) {
                if(isset($postResult['errorMessages'])) {
                    $result = $this->response("Please fill all required fields in all languages", 400, null, false, false, true, $postResult['errorMessages'], $postResult['noty']);
                }else{
                    $result = $this->response('You post could not be saved. Please try again later', 500, null, false, false, false, [], $postResult['noty']);
                }
            }else{
                $redirectParams = self::redirectParams($request->redirect, $postResult['postType'], $postResult['postID']);
                $result = $this->response('Your post was successfully saved', 200, $postResult['postID'], $redirectParams['view'], $redirectParams['redirectUrl'], false, [], $postResult['noty']);
            }

        }catch(\Exception $e){
            $result = $this->response($e->getMessage(), 500, null, false, false, false, [], []);
        }

        return $result;
    }
public function store(Request $request)
    {
        $data = $request->all();

        // check permissions
        if(isset($data['postID'])) {
            if(!User::hasAccess($request->postType, 'update', $data['postID'], true)) {
                return $this->noPermission();
            }
        }else{
            if(!User::hasAccess($request->postType, 'create')) {
                return $this->noPermission();
            }
        }

        $results = $this->fillEmptyTitles($data);
        $data = $results['data'];
        $firstFilledTitle = $results['firstFilledTitle'];

        // generate a unique slug
        $postID = 0;
        if(isset($data['postID'])) {
            $postID = $data['postID'];
        }

        $data['slug'] = $this->fillEmptySlugs($data['slug'], $data['postType'], $firstFilledTitle, $postID);

        try{
            $postResult = Post::store($data);

            if($postResult['error']) {
                if(isset($postResult['errorMessages'])) {
                    $result = $this->response("Please fill all required fields in all languages", 400, null, false, false, true, $postResult['errorMessages'], $postResult['noty']);
                }else{
                    $result = $this->response('You post could not be saved. Please try again later', 500, null, false, false, false, [], $postResult['noty']);
                }
            }else{
                $redirectParams = self::redirectParams($request->redirect, $postResult['postType'], $postResult['postID']);
                $result = $this->response('Your post was successfully saved', 200, $postResult['postID'], $redirectParams['view'], $redirectParams['redirectUrl'], false, [], $postResult['noty']);
            }

        }catch(\Exception $e){
            $result = $this->response($e->getMessage(), 500, null, false, false, false, [], []);
        }

        return $result;
    }
public function store ( Request $ request ) { $ data = $ request -> all ( ) ; // check permissions if ( isset ( $ data [ 'postID' ] ) ) { if ( ! User :: hasAccess ( $ request -> postType , 'update' , $ data [ 'postID' ] , true ) ) { return $ this -> noPermission ( ) ; } } else { if ( ! User :: hasAccess ( $ request -> postType , 'create' ) ) { return $ this -> noPermission ( ) ; } } $ results = $ this -> fillEmptyTitles ( $ data ) ; $ data = $ results [ 'data' ] ; $ firstFilledTitle = $ results [ 'firstFilledTitle' ] ; // generate a unique slug $ postID = 0 ; if ( isset ( $ data [ 'postID' ] ) ) { $ postID = $ data [ 'postID' ] ; } $ data [ 'slug' ] = $ this -> fillEmptySlugs ( $ data [ 'slug' ] , $ data [ 'postType' ] , $ firstFilledTitle , $ postID ) ; try { $ postResult = Post :: store ( $ data ) ; if ( $ postResult [ 'error' ] ) { if ( isset ( $ postResult [ 'errorMessages' ] ) ) { $ result = $ this -> response ( "Please fill all required fields in all languages" , 400 , null , false , false , true , $ postResult [ 'errorMessages' ] , $ postResult [ 'noty' ] ) ; } else { $ result = $ this -> response ( 'You post could not be saved. Please try again later' , 500 , null , false , false , false , [ ] , $ postResult [ 'noty' ] ) ; } } else { $ redirectParams = self :: redirectParams ( $ request -> redirect , $ postResult [ 'postType' ] , $ postResult [ 'postID' ] ) ; $ result = $ this -> response ( 'Your post was successfully saved' , 200 , $ postResult [ 'postID' ] , $ redirectParams [ 'view' ] , $ redirectParams [ 'redirectUrl' ] , false , [ ] , $ postResult [ 'noty' ] ) ; } } catch ( \ Exception $ e ) { $ result = $ this -> response ( $ e -> getMessage ( ) , 500 , null , false , false , false , [ ] , [ ] ) ; } return $ result ; }
This function is used to store the post in the database.
Is used to store the media relations too.

Request $request (parameter) post Request object with all data from the custom fields:
files - files array used to store the media relations (the files or images of a post)
formData - All custom fields with their values
languages - array with all languages where are the schedule date and time is stored
onlyInLang - a object array with languages and the value that contains (true or false) if the post is available in the specific language
postType - in which post type we are posting on
ID (Only in update) - used when we are updating a post not storing a new one

@param  Request $request
@return array
This function is used to store the post in the database . Is used to store the media relations too .