Illuminate\Support\Pluralizer::singular PHP Method

singular() public static method

Get the singular form of an English word.
public static singular ( string $value ) : string
$value string
return string
    public static function singular($value)
    {
        $singular = Inflector::singularize($value);
        return static::matchCase($singular, $value);
    }

Usage Example

 /**
  * Get the scaffolded template for a view
  *
  * @param  string $name
  * @return string Compiled template
  */
 protected function getScaffoldedTemplate($name)
 {
     $model = $this->cache->getModelName();
     // post
     $models = Pluralizer::plural($model);
     // posts
     $Models = ucwords($models);
     // Posts
     $Model = Pluralizer::singular($Models);
     // Post
     // Create and Edit views require form elements
     if ($name === 'create.blade' or $name === 'edit.blade') {
         $formElements = $this->makeFormElements();
         $this->template = str_replace('{{formElements}}', $formElements, $this->template);
     }
     // Replace template vars in view
     foreach (array('model', 'models', 'Models', 'Model') as $var) {
         $this->template = str_replace('{{' . $var . '}}', ${$var}, $this->template);
     }
     // And finally create the table rows
     list($headings, $fields, $editAndDeleteLinks) = $this->makeTableRows($model);
     $this->template = str_replace('{{headings}}', implode(PHP_EOL . "\t\t\t\t", $headings), $this->template);
     $this->template = str_replace('{{fields}}', implode(PHP_EOL . "\t\t\t\t\t", $fields) . PHP_EOL . $editAndDeleteLinks, $this->template);
     return $this->template;
 }
All Usage Examples Of Illuminate\Support\Pluralizer::singular