Themsaid\Langman\Manager::removeKey PHP Method

removeKey() public method

Remove a key from all language files.
public removeKey ( string $fileName, string $key ) : void
$fileName string
$key string
return void
    public function removeKey($fileName, $key)
    {
        foreach ($this->languages() as $language) {
            $filePath = $this->path . "/{$language}/{$fileName}.php";
            $fileContent = $this->getFileContent($filePath);
            Arr::forget($fileContent, $key);
            $this->writeFile($filePath, $fileContent);
        }
    }

Usage Example

 /**
  * Rename the given oldKey to the newKey.
  *
  * @return void
  */
 private function renameKey()
 {
     try {
         list($file, $key) = explode('.', $this->argument('oldKey'), 2);
     } catch (\ErrorException $e) {
         $this->error('Could not recognize the key you want to rename.');
         return;
     }
     if (Str::contains($this->argument('newKey'), '.')) {
         $this->error('Please provide the new key must not contain a dot.');
         return;
     }
     $newKey = preg_replace('/(\\w+)$/i', $this->argument('newKey'), $key);
     $files = $this->manager->files()[$file];
     $currentValues = [];
     foreach ($files as $languageKey => $filePath) {
         $content = Arr::dot($this->manager->getFileContent($filePath));
         $currentValues[$languageKey] = isset($content[$key]) ? $content[$key] : '';
     }
     $this->manager->removeKey($file, $key);
     $this->manager->fillKeys($file, [$newKey => $currentValues]);
 }
All Usage Examples Of Themsaid\Langman\Manager::removeKey