src/Post/Post.php
public function create($postArr)
    {
        $userId = null;
        if (Auth::check()) {
            $userId = Auth::user()->id;
        }

        $default = [
            'post_author'    => $userId,
            'post_content'   => '',
            'post_title'     => '',
            'post_excerpt'   => '',
            'post_status'    => 'draft',
            'post_type'      => 'post',
            'comment_status' => '',
            'post_parent'    => 0,
            'menu_order'     => 0,
        ];

        $postArr = array_unique(array_merge($default, $postArr));

        $postArr[ 'guid' ] = sha1(time());

        if (empty($postArr[ 'post_title' ])) {
            return new EtherError('Post title must be provided');
        }

        if (isset($postArr[ 'post_slug' ]) && ! empty($postArr[ 'post_slug' ])) {
            $postArr[ 'post_slug' ] = $this->postRepository->sluggable($postArr[ 'post_slug' ], 'post_slug');
        } else {
            $postArr[ 'post_slug' ] = $this->postRepository->sluggable($postArr[ 'post_title' ], 'post_slug');
        }
        try {
            $post = $this->postRepository->create($postArr);
        } catch (\Exception $e) {
            return new EtherError($e);
        }

        return $post;
    }
public function create($postArr)
    {
        $userId = null;
        if (Auth::check()) {
            $userId = Auth::user()->id;
        }

        $default = [
            'post_author'    => $userId,
            'post_content'   => '',
            'post_title'     => '',
            'post_excerpt'   => '',
            'post_status'    => 'draft',
            'post_type'      => 'post',
            'comment_status' => '',
            'post_parent'    => 0,
            'menu_order'     => 0,
        ];

        $postArr = array_unique(array_merge($default, $postArr));

        $postArr[ 'guid' ] = sha1(time());

        if (empty($postArr[ 'post_title' ])) {
            return new EtherError('Post title must be provided');
        }

        if (isset($postArr[ 'post_slug' ]) && ! empty($postArr[ 'post_slug' ])) {
            $postArr[ 'post_slug' ] = $this->postRepository->sluggable($postArr[ 'post_slug' ], 'post_slug');
        } else {
            $postArr[ 'post_slug' ] = $this->postRepository->sluggable($postArr[ 'post_title' ], 'post_slug');
        }
        try {
            $post = $this->postRepository->create($postArr);
        } catch (\Exception $e) {
            return new EtherError($e);
        }

        return $post;
    }
public function create ( $ postArr ) { $ userId = null ; if ( Auth :: check ( ) ) { $ userId = Auth :: user ( ) -> id ; } $ default = [ 'post_author' => $ userId , 'post_content' => '' , 'post_title' => '' , 'post_excerpt' => '' , 'post_status' => 'draft' , 'post_type' => 'post' , 'comment_status' => '' , 'post_parent' => 0 , 'menu_order' => 0 , ] ; $ postArr = array_unique ( array_merge ( $ default , $ postArr ) ) ; $ postArr [ 'guid' ] = sha1 ( time ( ) ) ; if ( empty ( $ postArr [ 'post_title' ] ) ) { return new EtherError ( 'Post title must be provided' ) ; } if ( isset ( $ postArr [ 'post_slug' ] ) && ! empty ( $ postArr [ 'post_slug' ] ) ) { $ postArr [ 'post_slug' ] = $ this -> postRepository -> sluggable ( $ postArr [ 'post_slug' ] , 'post_slug' ) ; } else { $ postArr [ 'post_slug' ] = $ this -> postRepository -> sluggable ( $ postArr [ 'post_title' ] , 'post_slug' ) ; } try { $ post = $ this -> postRepository -> create ( $ postArr ) ; } catch ( \ Exception $ e ) { return new EtherError ( $ e ) ; } return $ post ; }
Inserts a new post and return the post id

@param array $postArr

@return integer|EtherError|null
Inserts a new post and return the post id