private function generateTitleAndSlug($form)
    {
        $errors = [];
        $requiredMessage = " is required";
        $defaultLanguage = Language::getDefault();
        $result = $form;

        $defaultLanguageTitle = '';
        // title in default language should no be empty
        if(isset($form['title']) 
            && isset($form['title'][$defaultLanguage->slug]) 
            && $form['title'][$defaultLanguage->slug] != ""
        ) {
            $defaultLanguageTitle = $form['title'][$defaultLanguage->slug];
            $newSlug = parent::generateSlug($defaultLanguageTitle, 'categories', 'categoryID', App::getLocale(), 0, true);
        }else{
            $errors['title_'.$defaultLanguage['slug']] = array('Title '.$requiredMessage. " in ".$defaultLanguage['name']);
        }

        if ($defaultLanguageTitle) {
            // loop throw data in each language and generate title and slug if there are empty
            $languages = Language::all();
            foreach($form as $formDataKey => $formDataValue){
                foreach($languages as $language){
                    if($formDataKey == "title" && !$language['isDefault']) {
                        if(!$formDataValue[$language['slug']]) {
                            if($defaultLanguageTitle) {
                                $formDataValue[$language['slug']] = $defaultLanguageTitle;
                            }
                        }
                    }

                    if($formDataKey == "slug") {
                        if(!$formDataValue[$language['slug']]) {
                            $formDataValue[$language['slug']] = $newSlug;
                        }
                    }
                }

                $result[$formDataKey] = $formDataValue;
            }
        }

        return [
            "form" => $result,
            "errors" => $errors
        ];
    }
private function generateTitleAndSlug($form)
    {
        $errors = [];
        $requiredMessage = " is required";
        $defaultLanguage = Language::getDefault();
        $result = $form;

        $defaultLanguageTitle = '';
        // title in default language should no be empty
        if(isset($form['title']) 
            && isset($form['title'][$defaultLanguage->slug]) 
            && $form['title'][$defaultLanguage->slug] != ""
        ) {
            $defaultLanguageTitle = $form['title'][$defaultLanguage->slug];
            $newSlug = parent::generateSlug($defaultLanguageTitle, 'categories', 'categoryID', App::getLocale(), 0, true);
        }else{
            $errors['title_'.$defaultLanguage['slug']] = array('Title '.$requiredMessage. " in ".$defaultLanguage['name']);
        }

        if ($defaultLanguageTitle) {
            // loop throw data in each language and generate title and slug if there are empty
            $languages = Language::all();
            foreach($form as $formDataKey => $formDataValue){
                foreach($languages as $language){
                    if($formDataKey == "title" && !$language['isDefault']) {
                        if(!$formDataValue[$language['slug']]) {
                            if($defaultLanguageTitle) {
                                $formDataValue[$language['slug']] = $defaultLanguageTitle;
                            }
                        }
                    }

                    if($formDataKey == "slug") {
                        if(!$formDataValue[$language['slug']]) {
                            $formDataValue[$language['slug']] = $newSlug;
                        }
                    }
                }

                $result[$formDataKey] = $formDataValue;
            }
        }

        return [
            "form" => $result,
            "errors" => $errors
        ];
    }
private function generateTitleAndSlug ( $ form ) { $ errors = [ ] ; $ requiredMessage = " is required" ; $ defaultLanguage = Language :: getDefault ( ) ; $ result = $ form ; $ defaultLanguageTitle = '' ; // title in default language should no be empty if ( isset ( $ form [ 'title' ] ) && isset ( $ form [ 'title' ] [ $ defaultLanguage -> slug ] ) && $ form [ 'title' ] [ $ defaultLanguage -> slug ] != "" ) { $ defaultLanguageTitle = $ form [ 'title' ] [ $ defaultLanguage -> slug ] ; $ newSlug = parent :: generateSlug ( $ defaultLanguageTitle , 'categories' , 'categoryID' , App :: getLocale ( ) , 0 , true ) ; } else { $ errors [ 'title_' . $ defaultLanguage [ 'slug' ] ] = array ( 'Title ' . $ requiredMessage . " in " . $ defaultLanguage [ 'name' ] ) ; } if ( $ defaultLanguageTitle ) { // loop throw data in each language and generate title and slug if there are empty $ languages = Language :: all ( ) ; foreach ( $ form as $ formDataKey => $ formDataValue ) { foreach ( $ languages as $ language ) { if ( $ formDataKey == "title" && ! $ language [ 'isDefault' ] ) { if ( ! $ formDataValue [ $ language [ 'slug' ] ] ) { if ( $ defaultLanguageTitle ) { $ formDataValue [ $ language [ 'slug' ] ] = $ defaultLanguageTitle ; } } } if ( $ formDataKey == "slug" ) { if ( ! $ formDataValue [ $ language [ 'slug' ] ] ) { $ formDataValue [ $ language [ 'slug' ] ] = $ newSlug ; } } } $ result [ $ formDataKey ] = $ formDataValue ; } } return [ "form" => $ result , "errors" => $ errors ] ; }
If title and slug are empty fill them with the default language title.

@param  array $form
@return array
@throws \Exception
If title and slug are empty fill them with the default language title .