public static function createTable($postTypeSlug, $fields = [], $hasCategories = false, $hasTags = false, $createRoutes = true, $controller = null)
    {
        self::$customFieldsArray = [];

        // create new table for the posts of the post type
        $isTableCreated = Schema::create(
            $postTypeSlug, function ($table) use ($fields) {
                // create general fields
                $table->bigIncrements("postID");
                $table->unsignedInteger("createdByUserID")->nullable();
                $table->json("title")->nullable();
                $table->json("content")->nullable();
                $table->json("customFields")->nullable();
                $table->unsignedInteger("featuredImageID")->nullable();
                $table->unsignedInteger("featuredVideoID")->nullable();
                $table->json("status")->nullable();
                $table->datetime("published_at")->nullable()->index();
                $table->json("slug")->nullable();

                $table->foreign('createdByUserID')
                    ->references('userID')->on('users')
                    ->onDelete('cascade');

                $table->foreign('featuredImageID')
                    ->references('mediaID')->on('media')
                    ->onDelete('set null');

                $table->foreign('featuredVideoID')
                    ->references('mediaID')->on('media')
                    ->onDelete('set null');

                $post = new PostType();
                $usedSlugs = [];
                $usedSlugs = array_merge($usedSlugs, $post->fillable);

                foreach($fields as $field){
                    // generate unique slugs for every field
                    if(!isset($field['slug']) || $field['slug'] == "") {
                        $slug = self::generateSlug($field['name'], $usedSlugs);
                    }else{
                        $slug = self::generateSlug($field['slug'], $usedSlugs);
                    }
                    $usedSlugs[] = $slug;

                    $field['slug'] = $slug;
                    array_push(self::$customFieldsArray, $field);

                    // create other fields
                    self::createDatabaseFields($table, $field, $slug);
                }
                $table->timestamps();
            }
        );

        self::createMediaRelationsTable($postTypeSlug);

        if($hasCategories) {
            self::createCategoryRelationsTable($postTypeSlug);
        }

        if($hasTags) {
            self::createTagRelationsTable($postTypeSlug);
        }

        if($createRoutes) {
            self::createRouteFile($postTypeSlug, $controller);
        }

        self::createVirtualColumnsForSlug($postTypeSlug);

        return self::$customFieldsArray;
    }
public static function createTable($postTypeSlug, $fields = [], $hasCategories = false, $hasTags = false, $createRoutes = true, $controller = null)
    {
        self::$customFieldsArray = [];

        // create new table for the posts of the post type
        $isTableCreated = Schema::create(
            $postTypeSlug, function ($table) use ($fields) {
                // create general fields
                $table->bigIncrements("postID");
                $table->unsignedInteger("createdByUserID")->nullable();
                $table->json("title")->nullable();
                $table->json("content")->nullable();
                $table->json("customFields")->nullable();
                $table->unsignedInteger("featuredImageID")->nullable();
                $table->unsignedInteger("featuredVideoID")->nullable();
                $table->json("status")->nullable();
                $table->datetime("published_at")->nullable()->index();
                $table->json("slug")->nullable();

                $table->foreign('createdByUserID')
                    ->references('userID')->on('users')
                    ->onDelete('cascade');

                $table->foreign('featuredImageID')
                    ->references('mediaID')->on('media')
                    ->onDelete('set null');

                $table->foreign('featuredVideoID')
                    ->references('mediaID')->on('media')
                    ->onDelete('set null');

                $post = new PostType();
                $usedSlugs = [];
                $usedSlugs = array_merge($usedSlugs, $post->fillable);

                foreach($fields as $field){
                    // generate unique slugs for every field
                    if(!isset($field['slug']) || $field['slug'] == "") {
                        $slug = self::generateSlug($field['name'], $usedSlugs);
                    }else{
                        $slug = self::generateSlug($field['slug'], $usedSlugs);
                    }
                    $usedSlugs[] = $slug;

                    $field['slug'] = $slug;
                    array_push(self::$customFieldsArray, $field);

                    // create other fields
                    self::createDatabaseFields($table, $field, $slug);
                }
                $table->timestamps();
            }
        );

        self::createMediaRelationsTable($postTypeSlug);

        if($hasCategories) {
            self::createCategoryRelationsTable($postTypeSlug);
        }

        if($hasTags) {
            self::createTagRelationsTable($postTypeSlug);
        }

        if($createRoutes) {
            self::createRouteFile($postTypeSlug, $controller);
        }

        self::createVirtualColumnsForSlug($postTypeSlug);

        return self::$customFieldsArray;
    }
public static function createTable ( $ postTypeSlug , $ fields = [ ] , $ hasCategories = false , $ hasTags = false , $ createRoutes = true , $ controller = null ) { self :: $ customFieldsArray = [ ] ; // create new table for the posts of the post type $ isTableCreated = Schema :: create ( $ postTypeSlug , function ( $ table ) use ( $ fields ) { // create general fields $ table -> bigIncrements ( "postID" ) ; $ table -> unsignedInteger ( "createdByUserID" ) -> nullable ( ) ; $ table -> json ( "title" ) -> nullable ( ) ; $ table -> json ( "content" ) -> nullable ( ) ; $ table -> json ( "customFields" ) -> nullable ( ) ; $ table -> unsignedInteger ( "featuredImageID" ) -> nullable ( ) ; $ table -> unsignedInteger ( "featuredVideoID" ) -> nullable ( ) ; $ table -> json ( "status" ) -> nullable ( ) ; $ table -> datetime ( "published_at" ) -> nullable ( ) -> index ( ) ; $ table -> json ( "slug" ) -> nullable ( ) ; $ table -> foreign ( 'createdByUserID' ) -> references ( 'userID' ) -> on ( 'users' ) -> onDelete ( 'cascade' ) ; $ table -> foreign ( 'featuredImageID' ) -> references ( 'mediaID' ) -> on ( 'media' ) -> onDelete ( 'set null' ) ; $ table -> foreign ( 'featuredVideoID' ) -> references ( 'mediaID' ) -> on ( 'media' ) -> onDelete ( 'set null' ) ; $ post = new PostType ( ) ; $ usedSlugs = [ ] ; $ usedSlugs = array_merge ( $ usedSlugs , $ post -> fillable ) ; foreach ( $ fields as $ field ) { // generate unique slugs for every field if ( ! isset ( $ field [ 'slug' ] ) || $ field [ 'slug' ] == "" ) { $ slug = self :: generateSlug ( $ field [ 'name' ] , $ usedSlugs ) ; } else { $ slug = self :: generateSlug ( $ field [ 'slug' ] , $ usedSlugs ) ; } $ usedSlugs [ ] = $ slug ; $ field [ 'slug' ] = $ slug ; array_push ( self :: $ customFieldsArray , $ field ) ; // create other fields self :: createDatabaseFields ( $ table , $ field , $ slug ) ; } $ table -> timestamps ( ) ; } ) ; self :: createMediaRelationsTable ( $ postTypeSlug ) ; if ( $ hasCategories ) { self :: createCategoryRelationsTable ( $ postTypeSlug ) ; } if ( $ hasTags ) { self :: createTagRelationsTable ( $ postTypeSlug ) ; } if ( $ createRoutes ) { self :: createRouteFile ( $ postTypeSlug , $ controller ) ; } self :: createVirtualColumnsForSlug ( $ postTypeSlug ) ; return self :: $ customFieldsArray ; }
Create table and his columns when post type is created.

@param  $postTypeSlug
@param  $fields
@return array
Create table and his columns when post type is created .