public function detailsJSON($lang, $postTypeSlug, $id)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess($postTypeSlug, 'update', $id, true)) {
            return $this->noPermission();
        }

        // post type
        $currentPostType = PostType::findBySlug($postTypeSlug);
        // get post
        $post = (new Post())->setTable($postTypeSlug)->find($id);

        if(!$post) {
            return $this->response("There is no post with ID: " . $id, 404);
        }
        // posts url
        $href = $post->href;

        // we need fields non-translated so we can play around with them in vuejs
        $post->setAutoTranslate(false);

        // the fields that are translatable
        $translatableFields = $this->getTranslatableFields($postTypeSlug);

        // get all related media and structure them for the post
        $media = $this->getPostRelatedMedia($id, $post, $postTypeSlug, $translatableFields);

        // handle custom fields
        $customFieldGroups = CustomFieldGroup::findGroups('post-type', 'update', $id, $postTypeSlug);
        $customFieldOBJ = new CustomField();
        if($post->customFields) {
            $customFieldOBJ->constructValues($customFieldGroups, $post->customFields);
            $media = array_merge($media, $customFieldOBJ->getMedia());
        }

        // Categories (options to select)
        $categories = array_values(Category::where("postTypeID", $currentPostType->postTypeID)->get()->toArray());

        // selected categories of this post
        $selectedCategories = [];
        if($currentPostType->hasCategories) {
            $selectedCategories = $this->getPostSelectedCategories($id, $postTypeSlug);
        }

        // selected tags of this post
        $selectedTags = [];
        if($currentPostType->hasTags) {
            $selectedTags = $this->getPostSelectedTags($id, $postTypeSlug);
        }

        $response = array(
            'post' => [
                'title' => $post->title,
                'content' => $post->content,
                'status' => $post->status,
                'slug' => $post->slug,
                'href' => $href,
                'media' => $media,
                'published_at' => $post->published_at,
                'selectedCategories' => $selectedCategories,
                'postTypeID' => $currentPostType->postTypeID,
                'hasCategories' => $currentPostType->hasCategories,
                'isCategoryRequired' => $currentPostType->isCategoryRequired,
                'selectedTags' => $selectedTags,
                'hasTags' => $currentPostType->hasTags,
                'isTagRequired' => $currentPostType->isTagRequired,
                'isFeaturedImageRequired' => $currentPostType->isFeaturedImageRequired,
                'createdByUserID' => $post->createdByUserID,
            ],
            'customFieldsValues' => $customFieldOBJ->getCustomFieldValues(),
            'customFieldsGroups' => $customFieldGroups,
            'postTypeFieldsValues' => $this->getPostTypeFieldsValues($postTypeSlug, $post),
            'categories' => $categories,
            'languages' => Language::all(),
            'users' => User::all(),
        );

        // Fire event
        $response['events'] = Event::fire('post:pre_update', [$response]);

        return $response;
    }
public function detailsJSON($lang, $postTypeSlug, $id)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess($postTypeSlug, 'update', $id, true)) {
            return $this->noPermission();
        }

        // post type
        $currentPostType = PostType::findBySlug($postTypeSlug);
        // get post
        $post = (new Post())->setTable($postTypeSlug)->find($id);

        if(!$post) {
            return $this->response("There is no post with ID: " . $id, 404);
        }
        // posts url
        $href = $post->href;

        // we need fields non-translated so we can play around with them in vuejs
        $post->setAutoTranslate(false);

        // the fields that are translatable
        $translatableFields = $this->getTranslatableFields($postTypeSlug);

        // get all related media and structure them for the post
        $media = $this->getPostRelatedMedia($id, $post, $postTypeSlug, $translatableFields);

        // handle custom fields
        $customFieldGroups = CustomFieldGroup::findGroups('post-type', 'update', $id, $postTypeSlug);
        $customFieldOBJ = new CustomField();
        if($post->customFields) {
            $customFieldOBJ->constructValues($customFieldGroups, $post->customFields);
            $media = array_merge($media, $customFieldOBJ->getMedia());
        }

        // Categories (options to select)
        $categories = array_values(Category::where("postTypeID", $currentPostType->postTypeID)->get()->toArray());

        // selected categories of this post
        $selectedCategories = [];
        if($currentPostType->hasCategories) {
            $selectedCategories = $this->getPostSelectedCategories($id, $postTypeSlug);
        }

        // selected tags of this post
        $selectedTags = [];
        if($currentPostType->hasTags) {
            $selectedTags = $this->getPostSelectedTags($id, $postTypeSlug);
        }

        $response = array(
            'post' => [
                'title' => $post->title,
                'content' => $post->content,
                'status' => $post->status,
                'slug' => $post->slug,
                'href' => $href,
                'media' => $media,
                'published_at' => $post->published_at,
                'selectedCategories' => $selectedCategories,
                'postTypeID' => $currentPostType->postTypeID,
                'hasCategories' => $currentPostType->hasCategories,
                'isCategoryRequired' => $currentPostType->isCategoryRequired,
                'selectedTags' => $selectedTags,
                'hasTags' => $currentPostType->hasTags,
                'isTagRequired' => $currentPostType->isTagRequired,
                'isFeaturedImageRequired' => $currentPostType->isFeaturedImageRequired,
                'createdByUserID' => $post->createdByUserID,
            ],
            'customFieldsValues' => $customFieldOBJ->getCustomFieldValues(),
            'customFieldsGroups' => $customFieldGroups,
            'postTypeFieldsValues' => $this->getPostTypeFieldsValues($postTypeSlug, $post),
            'categories' => $categories,
            'languages' => Language::all(),
            'users' => User::all(),
        );

        // Fire event
        $response['events'] = Event::fire('post:pre_update', [$response]);

        return $response;
    }
public function detailsJSON ( $ lang , $ postTypeSlug , $ id ) { // check if user has permissions to access this link if ( ! User :: hasAccess ( $ postTypeSlug , 'update' , $ id , true ) ) { return $ this -> noPermission ( ) ; } // post type $ currentPostType = PostType :: findBySlug ( $ postTypeSlug ) ; // get post $ post = ( new Post ( ) ) -> setTable ( $ postTypeSlug ) -> find ( $ id ) ; if ( ! $ post ) { return $ this -> response ( "There is no post with ID: " . $ id , 404 ) ; } // posts url $ href = $ post -> href ; // we need fields non-translated so we can play around with them in vuejs $ post -> setAutoTranslate ( false ) ; // the fields that are translatable $ translatableFields = $ this -> getTranslatableFields ( $ postTypeSlug ) ; // get all related media and structure them for the post $ media = $ this -> getPostRelatedMedia ( $ id , $ post , $ postTypeSlug , $ translatableFields ) ; // handle custom fields $ customFieldGroups = CustomFieldGroup :: findGroups ( 'post-type' , 'update' , $ id , $ postTypeSlug ) ; $ customFieldOBJ = new CustomField ( ) ; if ( $ post -> customFields ) { $ customFieldOBJ -> constructValues ( $ customFieldGroups , $ post -> customFields ) ; $ media = array_merge ( $ media , $ customFieldOBJ -> getMedia ( ) ) ; } // Categories (options to select) $ categories = array_values ( Category :: where ( "postTypeID" , $ currentPostType -> postTypeID ) -> get ( ) -> toArray ( ) ) ; // selected categories of this post $ selectedCategories = [ ] ; if ( $ currentPostType -> hasCategories ) { $ selectedCategories = $ this -> getPostSelectedCategories ( $ id , $ postTypeSlug ) ; } // selected tags of this post $ selectedTags = [ ] ; if ( $ currentPostType -> hasTags ) { $ selectedTags = $ this -> getPostSelectedTags ( $ id , $ postTypeSlug ) ; } $ response = array ( 'post' => [ 'title' => $ post -> title , 'content' => $ post -> content , 'status' => $ post -> status , 'slug' => $ post -> slug , 'href' => $ href , 'media' => $ media , 'published_at' => $ post -> published_at , 'selectedCategories' => $ selectedCategories , 'postTypeID' => $ currentPostType -> postTypeID , 'hasCategories' => $ currentPostType -> hasCategories , 'isCategoryRequired' => $ currentPostType -> isCategoryRequired , 'selectedTags' => $ selectedTags , 'hasTags' => $ currentPostType -> hasTags , 'isTagRequired' => $ currentPostType -> isTagRequired , 'isFeaturedImageRequired' => $ currentPostType -> isFeaturedImageRequired , 'createdByUserID' => $ post -> createdByUserID , ] , 'customFieldsValues' => $ customFieldOBJ -> getCustomFieldValues ( ) , 'customFieldsGroups' => $ customFieldGroups , 'postTypeFieldsValues' => $ this -> getPostTypeFieldsValues ( $ postTypeSlug , $ post ) , 'categories' => $ categories , 'languages' => Language :: all ( ) , 'users' => User :: all ( ) , ) ; // Fire event $ response [ 'events' ] = Event :: fire ( 'post:pre_update' , [ $ response ] ) ; return $ response ; }
All required data for post update form.

@param  string $lang
@param  string $postTypeSlug
@param  int    $id
@return array
@throws \Exception
All required data for post update form .