public function afterCreate($payload)
    {
        if (config('cms.auto-translate', false)) {
            $entry = $payload->toArray();

            unset($entry['created_at']);
            unset($entry['updated_at']);
            unset($entry['translations']);
            unset($entry['is_published']);
            unset($entry['published_at']);
            unset($entry['id']);

            foreach (config('cms.languages') as $code => $language) {
                if ($code != config('cms.default-language')) {
                    $translateClient = new TranslateClient(config('cms.default-language'), $code);
                    $translation = [
                        'lang' => $code,
                        'template' => 'show',
                    ];

                    foreach ($entry as $key => $value) {
                        $translation[$key] = $value;

                        if (!empty($value)) {
                            $translation[$key] = json_decode(json_encode($translateClient->translate(strip_tags($value))));
                        }
                    }

                    // not the biggest fan of this but it works
                    if (empty($translation['blocks'])) {
                        $translation['blocks'] = "{}";
                    }

                    if (isset($translation['url'])) {
                        $translation['url'] = app(CmsService::class)->convertToURL($translation['url']);
                    }

                    $entityId = $payload->id;
                    $entityType = get_class($payload);
                    app(TranslationRepository::class)->createOrUpdate($entityId, $entityType, $code, $translation);
                }
            }
        }
    }
public function afterCreate($payload)
    {
        if (config('cms.auto-translate', false)) {
            $entry = $payload->toArray();

            unset($entry['created_at']);
            unset($entry['updated_at']);
            unset($entry['translations']);
            unset($entry['is_published']);
            unset($entry['published_at']);
            unset($entry['id']);

            foreach (config('cms.languages') as $code => $language) {
                if ($code != config('cms.default-language')) {
                    $translateClient = new TranslateClient(config('cms.default-language'), $code);
                    $translation = [
                        'lang' => $code,
                        'template' => 'show',
                    ];

                    foreach ($entry as $key => $value) {
                        $translation[$key] = $value;

                        if (!empty($value)) {
                            $translation[$key] = json_decode(json_encode($translateClient->translate(strip_tags($value))));
                        }
                    }

                    // not the biggest fan of this but it works
                    if (empty($translation['blocks'])) {
                        $translation['blocks'] = "{}";
                    }

                    if (isset($translation['url'])) {
                        $translation['url'] = app(CmsService::class)->convertToURL($translation['url']);
                    }

                    $entityId = $payload->id;
                    $entityType = get_class($payload);
                    app(TranslationRepository::class)->createOrUpdate($entityId, $entityType, $code, $translation);
                }
            }
        }
    }
public function afterCreate ( $ payload ) { if ( config ( 'cms.auto-translate' , false ) ) { $ entry = $ payload -> toArray ( ) ; unset ( $ entry [ 'created_at' ] ) ; unset ( $ entry [ 'updated_at' ] ) ; unset ( $ entry [ 'translations' ] ) ; unset ( $ entry [ 'is_published' ] ) ; unset ( $ entry [ 'published_at' ] ) ; unset ( $ entry [ 'id' ] ) ; foreach ( config ( 'cms.languages' ) as $ code => $ language ) { if ( $ code != config ( 'cms.default-language' ) ) { $ translateClient = new TranslateClient ( config ( 'cms.default-language' ) , $ code ) ; $ translation = [ 'lang' => $ code , 'template' => 'show' , ] ; foreach ( $ entry as $ key => $ value ) { $ translation [ $ key ] = $ value ; if ( ! empty ( $ value ) ) { $ translation [ $ key ] = json_decode ( json_encode ( $ translateClient -> translate ( strip_tags ( $ value ) ) ) ) ; } } // not the biggest fan of this but it works if ( empty ( $ translation [ 'blocks' ] ) ) { $ translation [ 'blocks' ] = "{}" ; } if ( isset ( $ translation [ 'url' ] ) ) { $ translation [ 'url' ] = app ( CmsService :: class ) -> convertToURL ( $ translation [ 'url' ] ) ; } $ entityId = $ payload -> id ; $ entityType = get_class ( $ payload ) ; app ( TranslationRepository :: class ) -> createOrUpdate ( $ entityId , $ entityType , $ code , $ translation ) ; } } } }
After the item is created in the database.

@param object $payload
After the item is created in the database .